MCPcopy Index your code
hub / github.com/webpack/webpack / _updateWithShortString

Method _updateWithShortString

lib/util/hash/wasm-hash.js:103–146  ·  view source on GitHub ↗

* Update with short string. * @param {string} data data * @param {BufferEncoding=} encoding encoding * @returns {void}

(data, encoding)

Source from the content-addressed store, hash-verified

101 * @returns {void}
102 */
103 _updateWithShortString(data, encoding) {
104 const { exports, buffered, mem, chunkSize } = this;
105 /** @type {number} */
106 let endPos;
107 if (data.length < 70) {
108 // eslint-disable-next-line unicorn/text-encoding-identifier-case
109 if (!encoding || encoding === "utf-8" || encoding === "utf8") {
110 endPos = buffered;
111 for (let i = 0; i < data.length; i++) {
112 const cc = data.charCodeAt(i);
113 if (cc < 0x80) {
114 mem[endPos++] = cc;
115 } else if (cc < 0x800) {
116 mem[endPos] = (cc >> 6) | 0xc0;
117 mem[endPos + 1] = (cc & 0x3f) | 0x80;
118 endPos += 2;
119 } else {
120 // bail-out for weird chars
121 endPos += mem.write(data.slice(i), endPos, encoding);
122 break;
123 }
124 }
125 } else if (encoding === "latin1") {
126 endPos = buffered;
127 for (let i = 0; i < data.length; i++) {
128 const cc = data.charCodeAt(i);
129 mem[endPos++] = cc;
130 }
131 } else {
132 endPos = buffered + mem.write(data, buffered, encoding);
133 }
134 } else {
135 endPos = buffered + mem.write(data, buffered, encoding);
136 }
137 if (endPos < chunkSize) {
138 this.buffered = endPos;
139 } else {
140 const l = endPos & ~(this.chunkSize - 1);
141 exports.update(l);
142 const newBuffered = endPos - l;
143 this.buffered = newBuffered;
144 if (newBuffered > 0) mem.copyWithin(0, l, endPos);
145 }
146 }
147
148 /**
149 * Update with buffer.

Callers 1

updateMethod · 0.95

Calls 3

writeMethod · 0.80
sliceMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected