MCPcopy
hub / github.com/webpack/webpack / compileBoundsSearch

Function compileBoundsSearch

lib/util/binarySearchBounds.js:85–113  ·  view source on GitHub ↗
(predicate, reversed, suffix, earlyOut)

Source from the content-addressed store, hash-verified

83 * @returns {Search<T>} The compiled binary search function.
84 */
85const compileBoundsSearch = (predicate, reversed, suffix, earlyOut) => {
86 const arg1 = compileSearch("A", `x${predicate}y`, reversed, ["y"], earlyOut);
87
88 const arg2 = compileSearch(
89 "P",
90 `c(x,y)${predicate}0`,
91 reversed,
92 ["y", "c"],
93 earlyOut
94 );
95
96 const fnHeader = "function dispatchBinarySearch";
97
98 const fnBody =
99 // eslint-disable-next-line no-multi-str
100 "(a,y,c,l,h){\
101if(typeof(c)==='function'){\
102return P(a,(l===void 0)?0:l|0,(h===void 0)?a.length-1:h|0,y,c)\
103}else{\
104return A(a,(c===void 0)?0:c|0,(l===void 0)?a.length-1:l|0,y)\
105}}\
106return dispatchBinarySearch";
107
108 const fnArgList = [arg1, arg2, fnHeader, suffix, fnBody, suffix];
109 const fnSource = fnArgList.join("");
110 // eslint-disable-next-line no-new-func
111 const result = new Function(fnSource);
112 return result();
113};
114
115const fns = {
116 ge: compileBoundsSearch(">=", false, "GE"),

Callers 1

Calls 2

compileSearchFunction · 0.85
resultFunction · 0.85

Tested by

no test coverage detected