From 6c8330845188798986d3b3bbca3c2654f47ac576 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Wed, 8 Apr 2015 10:48:27 +0200 Subject: [PATCH] Optimize Collection#get(). --- packages/xo-collection/src/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/xo-collection/src/index.js b/packages/xo-collection/src/index.js index a3415c770..dc446409c 100644 --- a/packages/xo-collection/src/index.js +++ b/packages/xo-collection/src/index.js @@ -152,11 +152,16 @@ export default class Collection extends EventEmitter { } get (key, defaultValue) { - if (arguments.length > 1 && !this.has(key)) { + if (this.has(key)) { + return this._map[key] + } + + if (arguments.length > 1) { return defaultValue } + + // Throws a NoSuchEntry. this._assertHas(key) - return this._map[key] } update (keyOrObjectWithId, valueIfKey = null) {