node/test/sequential/test-zlib-crc32-fast-api.js
Gürgün Dayıoğlu c85460b0ad
zlib: implement fast path for crc32
PR-URL: https://github.com/nodejs/node/pull/59813
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2025-09-14 00:39:58 +00:00

27 lines
739 B
JavaScript

// Flags: --expose-internals --no-warnings --allow-natives-syntax
'use strict';
const common = require('../common');
const assert = require('assert');
const zlib = require('zlib');
{
function testFastPath() {
const expected = 0xd87f7e0c; // zlib.crc32('test', 0)
assert.strictEqual(zlib.crc32('test', 0), expected);
return expected;
}
eval('%PrepareFunctionForOptimization(zlib.crc32)');
testFastPath();
eval('%OptimizeFunctionOnNextCall(zlib.crc32)');
testFastPath();
testFastPath();
if (common.isDebug) {
const { internalBinding } = require('internal/test/binding');
const { getV8FastApiCallCount } = internalBinding('debug');
assert.strictEqual(getV8FastApiCallCount('zlib.crc32'), 2);
}
}