8000 Buffer, refactor: optimising Buffer performance with primordials. · fibjs/fibjs@234e78b · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 234e78b

Browse files
committed
Buffer, refactor: 8000 optimising Buffer performance with primordials.
1 parent 665a69d commit 234e78b

File tree

5 files changed

+1244
-259
lines changed

5 files changed

+1244
-259
lines changed

fibjs/include/Buffer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,11 @@ class Buffer : public Buffer_base {
208208

209209
private:
210210
static void proto_compare(const v8::FunctionCallbackInfo<v8::Value>& args);
211-
static void proto_copy(const v8::FunctionCallbackInfo<v8::Value>& args);
212211
static void proto_equals(const v8::FunctionCallbackInfo<v8::Value>& args);
213-
static void proto_fill(const v8::FunctionCallbackInfo<v8::Value>& args);
214212
static void proto_indexOf(const v8::FunctionCallbackInfo<v8::Value>& args);
213+
214+
static void proto_copy(const v8::FunctionCallbackInfo<v8::Value>& args);
215+
static void proto_fill(const v8::FunctionCallbackInfo<v8::Value>& args);
215216
static void proto_write(const v8::FunctionCallbackInfo<v8::Value>& args);
216217

217218
private:

fibjs/scripts/buffer.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
var encoding = require('encoding');
2+
var {
3+
Uint8Array,
4+
ArrayBuffer,
5+
TypedArrayPrototypeFill,
6+
TypedArrayPrototypeCopyWithin,
7+
TypedArrayPrototypeSet
8+
} = require('./internal/primordials.js');
29

310
const poolSize = 8 * 1024;
411
let poolOffset, allocPool;
@@ -339,7 +346,7 @@ class Buffer extends Uint8Array {
339346
if (length !== buf_byteLength)
340347
buf = new Uint8Array(buf.buffer, buf.byteOffset, length);
341348

342-
this.set(buf, offset);
349+
TypedArrayPrototypeSet(this, buf, offset);
343350

344351
return length;
345352
}
@@ -374,7 +381,7 @@ class Buffer extends Uint8Array {
374381
throw new Error('end < offset');
375382

376383
if (typeof buf === 'number') {
377-
super.fill(buf, offset, end);
384+
TypedArrayPrototypeFill(this, buf, offset, end);
378385
return this;
379386
}
380387

@@ -383,18 +390,18 @@ class Buffer extends Uint8Array {
383390
if (buf_byteLength >= end - offset) {
384391
if (buf_byteLength > end - offset)
385392
buf = new Uint8Array(buf.buffer, buf.byteOffset, end - offset);
386-
this.set(buf, offset);
393+
TypedArrayPrototypeSet(this, buf, offset);
387394
} else {
388395
let fill_offset = offset;
389396

390-
this.set(buf, offset);
397+
TypedArrayPrototypeSet(this, buf, offset);
391398
offset += buf_byteLength;
392399

393400
while (offset < end) {
394401
if (buf_byteLength > end - offset)
395402
buf_byteLength = end - offset;
396403

397-
this.copyWithin(offset, fill_offset, fill_offset + buf_byteLength);
404+
TypedArrayPrototypeCopyWithin(this, offset, fill_offset, fill_offset + buf_byteLength);
398405
offset += buf_byteLength;
399406

400407
buf_byteLength *= 2;
@@ -1145,7 +1152,7 @@ class Buffer extends Uint8Array {
11451152
if (sourceStart != 0 || sourceEnd != buf.byteLength)
11461153
buf = new Uint8Array(buf.buffer, buf.byteOffset + sourceStart, sourceEnd - sourceStart);
11471154

1148-
target.set(buf, targetStart);
1155+
TypedArrayPrototypeSet(target, buf, targetStart);
11491156

11501157
return sourceEnd - sourceStart;
11511158

@@ -1292,7 +1299,7 @@ Buffer.concat = function (list, length) {
12921299
buf_byteLength = length - pos;
12931300
}
12941301

1295-
buffer.set(buf, pos);
1302+
TypedArrayPrototypeSet(buffer, buf, pos);
12961303
pos += buf_byteLength;
12971304
}
12981305

0 commit comments

Comments
 (0)
0