forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buffer: re-enable Fast API for Buffer.write
Re-enables fast Fast API for Buffer.write after fixing UTF8 handling. Fixes: nodejs#54521 PR-URL: nodejs#54526 Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Paolo Insogna <[email protected]>
- Loading branch information
Showing
2 changed files
with
165 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Flags: --expose-internals --no-warnings --allow-natives-syntax | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const { internalBinding } = require('internal/test/binding'); | ||
|
||
function testFastUtf8Write() { | ||
{ | ||
const buf = Buffer.from('\x80'); | ||
|
||
assert.strictEqual(buf[0], 194); | ||
assert.strictEqual(buf[1], 128); | ||
} | ||
|
||
{ | ||
const buf = Buffer.alloc(64); | ||
const newBuf = buf.subarray(0, buf.write('éñüçßÆ')); | ||
assert.deepStrictEqual(newBuf, Buffer.from([195, 169, 195, 177, 195, 188, 195, 167, 195, 159, 195, 134])); | ||
} | ||
|
||
{ | ||
const buf = Buffer.alloc(64); | ||
const newBuf = buf.subarray(0, buf.write('¿')); | ||
assert.deepStrictEqual(newBuf, Buffer.from([194, 191])); | ||
} | ||
|
||
{ | ||
const buf = Buffer.from(new ArrayBuffer(34), 0, 16); | ||
const str = Buffer.from([50, 83, 127, 39, 104, 8, 74, 65, 108, 123, 5, 4, 82, 10, 7, 53]).toString(); | ||
const newBuf = buf.subarray(0, buf.write(str)); | ||
assert.deepStrictEqual(newBuf, Buffer.from([ 50, 83, 127, 39, 104, 8, 74, 65, 108, 123, 5, 4, 82, 10, 7, 53])); | ||
} | ||
} | ||
|
||
eval('%PrepareFunctionForOptimization(Buffer.prototype.utf8Write)'); | ||
testFastUtf8Write(); | ||
eval('%OptimizeFunctionOnNextCall(Buffer.prototype.utf8Write)'); | ||
testFastUtf8Write(); | ||
|
||
if (common.isDebug) { | ||
const { getV8FastApiCallCount } = internalBinding('debug'); | ||
assert(getV8FastApiCallCount('buffer.writeString'), 4); | ||
} |