Skip to content

Commit

Permalink
faster iteration with static __stepNext method
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasq committed Dec 20, 2020
1 parent 87c1ecf commit 51ce13d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,11 @@ emitter, and the visitor is not called on them. The emitter does not throw, un-
errors are ignored. Errors accessing the top-level `dirname` are returned to the callback.


Traverse the directory


Changelog
---------

- 1.8.0 - new `makeError`, `compileVinterpolate`, `microtime`, `repeatFor`, `pairTo`, document repeatUntil, walkdir,
fix getProperty() for un-dotted names longer than 40 chars, faster getProperty
fix getProperty() for un-dotted names longer than 40 chars, faster getProperty, faster iteration
- 1.7.3 - new undocumented `repeatUntil`, `walkdir`
- 1.7.2 - fix escaped \] in globRegex char lists [...]
- 1.7.1 - new function `globRegex`
Expand Down
6 changes: 4 additions & 2 deletions qibl.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,20 +924,22 @@ function sortBy( items, getMetric ) {
// iterator() returns a traversal object with a method next().
// next() returns a data wrapper with properties {value, done}.
// If done is set then value is not to be used.
//
// __stepNext is 25% faster if static and reused (walking 10 items; 70% for 40)
function __stepNext() { this.__step(this.__state, this.__instance, this); return this; }
function makeIterator( step, makeState ) {
return function qiblIterator() {
// makeState is passed the object instance on which the iterator was called
var state = makeState && makeState(this) || {};
return {
value: 0,
done: false,
next: stepIterator,
next: __stepNext,
__step: step,
__state: state,
__instance: this,
};
}
function stepIterator() { this.__step(this.__state, this.__instance, this); return this; }
}
// install the iterator as Symbol.iterator if the node version supports symbols, else as ._iterator
function setIterator( obj, iterator ) {
Expand Down

0 comments on commit 51ce13d

Please sign in to comment.