Check whether byte slices are equal to each other using 32-bit comparisons. * * @param a First array to check equality. * @param b Second array to check equality. * @returns `true` if the arrays are equal, `false` otherwise. * * @private
(a: Uint8Array, b: Uint8Array)
| 26 | * @private |
| 27 | */ |
| 28 | function equals32Bit(a: Uint8Array, b: Uint8Array): boolean { |
| 29 | const len = a.length; |
| 30 | const compactOffset = 3 - ((a.byteOffset + 3) % 4); |
| 31 | const compactLen = Math.floor((len - compactOffset) / 4); |
| 32 | const compactA = new Uint32Array( |
| 33 | a.buffer, |
| 34 | a.byteOffset + compactOffset, |
| 35 | compactLen, |
| 36 | ); |
| 37 | const compactB = new Uint32Array( |
| 38 | b.buffer, |
| 39 | b.byteOffset + compactOffset, |
| 40 | compactLen, |
| 41 | ); |
| 42 | for (let i = 0; i < compactOffset; i++) { |
| 43 | if (a[i] !== b[i]) return false; |
| 44 | } |
| 45 | for (let i = 0; i < compactA.length; i++) { |
| 46 | if (compactA[i] !== compactB[i]) return false; |
| 47 | } |
| 48 | for (let i = compactOffset + compactLen * 4; i < len; i++) { |
| 49 | if (a[i] !== b[i]) return false; |
| 50 | } |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Byte length threshold for when to use 32-bit comparisons, based on |