Skip to content

Commit

Permalink
remove unnecessary new function & spread;
Browse files Browse the repository at this point in the history
- performance increase +20k~!
  • Loading branch information
lukeed committed Jul 11, 2018
1 parent 8a7f980 commit 9da1922
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ function print() {
let i=0, tmp, arr=this.keys, isMulti=!!~out.indexOf('\n');
for (; i < arr.length; i++) {
tmp = CODES[arr[i]]; // [x1, x2, rgx]
if (out.indexOf(tmp[0]) !== 0 || out.slice(-tmp[1].length) !== tmp[1]) {
out = tmp[0] + out.replace(tmp[2], tmp[0]) + tmp[1];
}
out = tmp[0] + out.replace(tmp[2], tmp[0]) + tmp[1];
isMulti && (out = out.replace(/(\r?\n)/g, `${tmp[1]}$1${tmp[0]}`));
}

return out;
}

function wrap(keys) {
let fn = (...args) => print.apply(fn, args);
Object.setPrototypeOf(fn, $);
fn.keys = keys;
let ctx = {};
let fn = Object.setPrototypeOf(print.bind(ctx), $);
ctx.keys = fn.keys = keys;
return fn;
}

Expand Down

0 comments on commit 9da1922

Please sign in to comment.