1 | import { u8aToU8a } from './toU8a.js';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export function u8aEq(a, b) {
|
17 | const u8aa = u8aToU8a(a);
|
18 | const u8ab = u8aToU8a(b);
|
19 | if (u8aa.length === u8ab.length) {
|
20 | const dvA = new DataView(u8aa.buffer, u8aa.byteOffset);
|
21 | const dvB = new DataView(u8ab.buffer, u8ab.byteOffset);
|
22 | const mod = (u8aa.length % 4) | 0;
|
23 | const length = (u8aa.length - mod) | 0;
|
24 | for (let i = 0; i < length; i += 4) {
|
25 | if (dvA.getUint32(i) !== dvB.getUint32(i)) {
|
26 | return false;
|
27 | }
|
28 | }
|
29 | for (let i = length, count = u8aa.length; i < count; i++) {
|
30 | if (u8aa[i] !== u8ab[i]) {
|
31 | return false;
|
32 | }
|
33 | }
|
34 | return true;
|
35 | }
|
36 | return false;
|
37 | }
|