MCPcopy
hub / github.com/webpack/webpack / bufferArraysEqual

Function bufferArraysEqual

lib/optimize/RealContentHashPlugin.js:56–80  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

54 * @returns {boolean} true if the concatenations are byte-equal
55 */
56const bufferArraysEqual = (a, b) => {
57 let aIdx = 0;
58 let aOff = 0;
59 let bIdx = 0;
60 let bOff = 0;
61 while (aIdx < a.length && bIdx < b.length) {
62 const aBuf = a[aIdx];
63 const bBuf = b[bIdx];
64 const len = Math.min(aBuf.length - aOff, bBuf.length - bOff);
65 if (aBuf.compare(bBuf, bOff, bOff + len, aOff, aOff + len) !== 0) {
66 return false;
67 }
68 aOff += len;
69 bOff += len;
70 if (aOff === aBuf.length) {
71 aIdx++;
72 aOff = 0;
73 }
74 if (bOff === bBuf.length) {
75 bIdx++;
76 bOff = 0;
77 }
78 }
79 return aIdx === a.length && bIdx === b.length;
80};
81
82/**
83 * Map sources to their buffer chunks and deduplicate by total byte content,

Callers 1

Calls 1

compareMethod · 0.80

Tested by

no test coverage detected