multipasta
Advanced tools
Comparing version
@@ -61,3 +61,2 @@ "use strict"; | ||
chunk = newChunk; | ||
start = 0; | ||
} | ||
@@ -64,0 +63,0 @@ const end = chunk.length; |
@@ -7,2 +7,5 @@ "use strict"; | ||
exports.make = make; | ||
function noopMatch(_, __) { | ||
return false; | ||
} | ||
function makeState(needle_) { | ||
@@ -19,3 +22,3 @@ const needle = new TextEncoder().encode(needle_); | ||
const needleFirstVariation = needle[needleFirstVariationIndex]; | ||
const exactMatch = new Function("chunk", "start", "return " + [...needle].filter((_, i) => i !== 0 || i !== needleFirstVariationIndex).map((b, i) => `chunk[start + ${i}] === ${b}`).join(" && ")); | ||
const exactMatch = "Buffer" in globalThis ? noopMatch : new Function("chunk", "start", "return " + [...needle].filter((_, i) => i !== 0 || i !== needleFirstVariationIndex).map((b, i) => `chunk[start + ${i}] === ${b}`).join(" && ")); | ||
return { | ||
@@ -22,0 +25,0 @@ needle, |
@@ -55,3 +55,2 @@ const constMaxPairs = 100; | ||
chunk = newChunk; | ||
start = 0; | ||
} | ||
@@ -58,0 +57,0 @@ const end = chunk.length; |
@@ -0,1 +1,4 @@ | ||
function noopMatch(_, __) { | ||
return false; | ||
} | ||
function makeState(needle_) { | ||
@@ -12,3 +15,3 @@ const needle = new TextEncoder().encode(needle_); | ||
const needleFirstVariation = needle[needleFirstVariationIndex]; | ||
const exactMatch = new Function("chunk", "start", "return " + [...needle].filter((_, i) => i !== 0 || i !== needleFirstVariationIndex).map((b, i) => `chunk[start + ${i}] === ${b}`).join(" && ")); | ||
const exactMatch = "Buffer" in globalThis ? noopMatch : new Function("chunk", "start", "return " + [...needle].filter((_, i) => i !== 0 || i !== needleFirstVariationIndex).map((b, i) => `chunk[start + ${i}] === ${b}`).join(" && ")); | ||
return { | ||
@@ -15,0 +18,0 @@ needle, |
{ | ||
"name": "multipasta", | ||
"version": "0.1.14", | ||
"version": "0.1.15", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -76,3 +76,2 @@ import { Continue, FailureReason, ReturnValue } from "../HeadersParser.js" | ||
chunk = newChunk | ||
start = 0 | ||
} | ||
@@ -79,0 +78,0 @@ const end = chunk.length |
@@ -15,2 +15,6 @@ interface SearchState { | ||
function noopMatch(_: Uint8Array, __: number): boolean { | ||
return false | ||
} | ||
function makeState(needle_: string): SearchState { | ||
@@ -30,11 +34,14 @@ const needle = new TextEncoder().encode(needle_) | ||
const exactMatch = new Function( | ||
"chunk", | ||
"start", | ||
"return " + | ||
[...needle] | ||
.filter((_, i) => i !== 0 || i !== needleFirstVariationIndex) | ||
.map((b, i) => `chunk[start + ${i}] === ${b}`) | ||
.join(" && "), | ||
) as (chunk: Uint8Array, start: number) => boolean | ||
const exactMatch = | ||
"Buffer" in globalThis | ||
? noopMatch | ||
: (new Function( | ||
"chunk", | ||
"start", | ||
"return " + | ||
[...needle] | ||
.filter((_, i) => i !== 0 || i !== needleFirstVariationIndex) | ||
.map((b, i) => `chunk[start + ${i}] === ${b}`) | ||
.join(" && "), | ||
) as (chunk: Uint8Array, start: number) => boolean) | ||
@@ -41,0 +48,0 @@ return { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
187339
0.26%3118
0.29%