From 8065a48e2e6c076d01b48bc524d0a305a41a31f1 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Wed, 27 Jan 2021 00:06:37 -0800 Subject: [PATCH] chore: golf & tweak perf --- src/index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index f25828f..0582cee 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,9 @@ export default function (obj, keys, val) { keys.split && (keys=keys.split('.')); var i=0, l=keys.length, t=obj, x, k; - for (; i < l; ++i) { - k = keys[i]; - if (k == '__proto__' || k == 'constructor' || k == 'prototype') continue; - x = t[k]; - t = t[k] = (i === l - 1 ? val : (x != null ? x : (!!~keys[i+1].indexOf('.') || !(+keys[i+1] > -1)) ? {} : [])); + for (; i < l;) { + k = keys[i++]; + if (k === '__proto__' || k === 'constructor' || k === 'prototype') continue; + t = t[k] = (i === l ? val : ((x=t[k]) != null ? x : (keys[i]*0 !== 0 || !!~keys[i].indexOf('.')) ? {} : [])); } }