Skip to content

Commit

Permalink
Improve performance of set
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocasciaro committed Jun 28, 2016
1 parent 7899af7 commit e0be6a1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
npm-debug.log
generated
coverage
.DS_Store
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ Access deep properties using a path
[![devDependency Status](https://david-dm.org/mariocasciaro/object-path/dev-status.svg)](https://david-dm.org/mariocasciaro/object-path#info=devDependencies)
![Downloads](http://img.shields.io/npm/dm/object-path.svg)


## Changelog

### 0.10.0

* Improved performance of `get`, `set`, and `push` by 2x-3x
* Introduced a benchmarking test suite
* **BREAKING CHANGE**: `del` will not delete not-own properties

## Install

### Node.js
Expand Down Expand Up @@ -108,6 +117,9 @@ model.del("a.b"); // obj.a.b is now undefined
model.has("a.b"); // false

```
### Notes

`object-path` is intentionally designed to access only an object's own properties

### Immutability

Expand Down
17 changes: 17 additions & 0 deletions benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var testObj = {
}
}

var testObj2

benchmark
.add('get existing', {
iterations: 100000,
Expand All @@ -32,4 +34,19 @@ benchmark
op.push(testObj, ['level1_a', 'level2_a', 'level3_a', 'level4_a', 'level5_a'], 'val')
}
})
.add('set non existing', {
iterations: 100000,
fn: function() {
op.set(testObj2, ['level1_a', 'level2_b', 'level3_b', 'level4_b', 'level5_b'], 'val')
},
beforeEach: function() {
testObj2 = {}
}
})
.add('set existing', {
iterations: 100000,
fn: function() {
op.set(testObj, ['level1_a', 'level2_a', 'level3_a', 'level4_a', 'level5_b'], 'val')
}
})
.run()
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
if (typeof path === 'number') {
path = [path];
}
if (isEmpty(path)) {
if (!path || path.length === 0) {
return obj;
}
if (typeof path === 'string') {
Expand Down

0 comments on commit e0be6a1

Please sign in to comment.