Skip to content

Commit

Permalink
some optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Dec 18, 2022
1 parent 041835b commit 4d1b116
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 2 additions & 3 deletions packages/core-js/internals/string-cooked.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ var toString = require('../internals/to-string');
var lengthOfArrayLike = require('../internals/length-of-array-like');

var $TypeError = TypeError;
var ArrayPrototype = Array.prototype;
var push = uncurryThis(ArrayPrototype.push);
var join = uncurryThis(ArrayPrototype.join);
var push = uncurryThis([].push);
var join = uncurryThis([].join);

module.exports = function cooked(template /* , ...substitutions */) {
var cookedTemplate = toIndexedObject(template);
Expand Down
14 changes: 8 additions & 6 deletions packages/core-js/modules/esnext.string.dedent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var getBuiltIn = require('../internals/get-built-in');
var makeBuiltIn = require('../internals/make-built-in');
var uncurryThis = require('../internals/function-uncurry-this');
var apply = require('../internals/function-apply');
var bindContext = require('../internals/function-bind-context');
var anObject = require('../internals/an-object');
var toObject = require('../internals/to-object');
var isCallable = require('../internals/is-callable');
Expand All @@ -18,9 +17,12 @@ var whitespaces = require('../internals/whitespaces');

var WeakMap = getBuiltIn('WeakMap');
var globalDedentRegistry = shared('GlobalDedentRegistry', new WeakMap());
var globalDedentRegistryHas = bindContext(globalDedentRegistry.has, globalDedentRegistry);
var globalDedentRegistryGet = bindContext(globalDedentRegistry.get, globalDedentRegistry);
var globalDedentRegistrySet = bindContext(globalDedentRegistry.set, globalDedentRegistry);

/* eslint-disable no-self-assign -- prototype methods protection */
globalDedentRegistry.has = globalDedentRegistry.has;
globalDedentRegistry.get = globalDedentRegistry.get;
globalDedentRegistry.set = globalDedentRegistry.set;
/* eslint-enable no-self-assign -- prototype methods protection */

var $Array = Array;
var $TypeError = TypeError;
Expand All @@ -41,14 +43,14 @@ var INVALID_CLOSING_LINE = 'Invalid closing line';

var dedentTemplateStringsArray = function (template) {
var rawInput = template.raw;
if (globalDedentRegistryHas(rawInput)) return globalDedentRegistryGet(rawInput);
if (globalDedentRegistry.has(rawInput)) return globalDedentRegistry.get(rawInput);
var raw = dedentStringsArray(rawInput);
var cookedArr = cookStrings(raw);
defineProperty(cookedArr, 'raw', {
value: freeze(raw)
});
freeze(cookedArr);
globalDedentRegistrySet(rawInput, cookedArr);
globalDedentRegistry.set(rawInput, cookedArr);
return cookedArr;
};

Expand Down

0 comments on commit 4d1b116

Please sign in to comment.