benjamn / wryware

A collection of packages that are probably a little too clever. Use at your own wrisk.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@wry/trie idea: speed up lookupArray by avoiding forEach and arrow function allocation

benjamn opened this issue · comments

In code that relies heavily on the Trie data structure provided by @wry/trie, this code has the potential to be hot, and thus worth optimizing for speed, even if that means rewriting it in a different style:

public lookupArray<T extends IArguments | any[]>(array: T): Data {
  let node: Trie<Data> = this;
  forEach.call(array, key => node = node.getChildTrie(key));
  return node.data || (node.data = this.makeData(slice.call(array)));
}