GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — buffer: faster type check · nodejs/node@ab6fae9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • buffer.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/buffer.js‎

Copy file name to clipboardExpand all lines: lib/buffer.js
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
const {
2525
Array,
26+
ArrayBufferIsView,
2627
ArrayIsArray,
2728
ArrayPrototypeForEach,
2829
MathFloor,
@@ -202,9 +203,9 @@ function toInteger(n, defaultVal) {
202203
}
203204

204205
function copyImpl(source, target, targetStart, sourceStart, sourceEnd) {
205-
if (!isUint8Array(source))
206+
if (!ArrayBufferIsView(source))
206207
throw new ERR_INVALID_ARG_TYPE('source', ['Buffer', 'Uint8Array'], source);
207-
if (!isUint8Array(target))
208+
if (!ArrayBufferIsView(target))
208209
throw new ERR_INVALID_ARG_TYPE('target', ['Buffer', 'Uint8Array'], target);
209210

210211
if (targetStart === undefined) {
@@ -219,30 +220,30 @@ function copyImpl(source, target, targetStart, sourceStart, sourceEnd) {
219220
sourceStart = 0;
220221
} else {
221222
sourceStart = NumberIsInteger(sourceStart) ? sourceStart : toInteger(sourceStart, 0);
222-
if (sourceStart < 0 || sourceStart > source.length)
223-
throw new ERR_OUT_OF_RANGE('sourceStart', `>= 0 && <= ${source.length}`, sourceStart);
223+
if (sourceStart < 0 || sourceStart > source.byteLength)
224+
throw new ERR_OUT_OF_RANGE('sourceStart', `>= 0 && <= ${source.byteLength}`, sourceStart);
224225
}
225226

226227
if (sourceEnd === undefined) {
227-
sourceEnd = source.length;
228+
sourceEnd = source.byteLength;
228229
} else {
229230
sourceEnd = NumberIsInteger(sourceEnd) ? sourceEnd : toInteger(sourceEnd, 0);
230231
if (sourceEnd < 0)
231232
throw new ERR_OUT_OF_RANGE('sourceEnd', '>= 0', sourceEnd);
232233
}
233234

234-
if (targetStart >= target.length || sourceStart >= sourceEnd)
235+
if (targetStart >= target.byteLength || sourceStart >= sourceEnd)
235236
return 0;
236237

237238
return _copyActual(source, target, targetStart, sourceStart, sourceEnd);
238239
}
239240

240241
function _copyActual(source, target, targetStart, sourceStart, sourceEnd) {
241-
if (sourceEnd - sourceStart > target.length - targetStart)
242-
sourceEnd = sourceStart + target.length - targetStart;
242+
if (sourceEnd - sourceStart > target.byteLength - targetStart)
243+
sourceEnd = sourceStart + target.byteLength - targetStart;
243244

244245
let nb = sourceEnd - sourceStart;
245-
const sourceLen = source.length - sourceStart;
246+
const sourceLen = source.byteLength - sourceStart;
246247
if (nb > sourceLen)
247248
nb = sourceLen;
248249

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.