Skip to content

Commit 138f38f

Browse files
committed
iterate over config keys instead of default keys, in most cases will be faster
1 parent 772cec5 commit 138f38f

File tree

8 files changed

+55
-43
lines changed

8 files changed

+55
-43
lines changed

amplitude.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,14 @@ var _parseConfig = function _parseConfig(options, config) {
236236
}
237237

238238
// validates config value is defined, is the correct type, and some additional value sanity checks
239-
var parseValidateLoad = function parseValidateLoad(key, expectedType) {
239+
var parseValidateAndLoad = function parseValidateAndLoad(key) {
240+
if (!DEFAULT_OPTIONS.hasOwnProperty(key)) {
241+
return; // skip bogus config values
242+
}
243+
240244
var inputValue = config[key];
241-
if (inputValue === undefined || !utils.validateInput(inputValue, key + ' option', expectedType)) {
245+
var expectedType = type(DEFAULT_OPTIONS[key]);
246+
if (!utils.validateInput(inputValue, key + ' option', expectedType)) {
242247
return;
243248
}
244249
if (expectedType === 'boolean') {
@@ -249,11 +254,10 @@ var _parseConfig = function _parseConfig(options, config) {
249254
}
250255
};
251256

252-
// the DEFAULT_OPTIONS object defines all valid keys, and provides expected types for the value
253-
for (var key in DEFAULT_OPTIONS) {
254-
if (DEFAULT_OPTIONS.hasOwnProperty(key)) {
255-
parseValidateLoad(key, type(DEFAULT_OPTIONS[key]));
256-
}
257+
for (var key in config) {
258+
if (config.hasOwnProperty(key)) {
259+
parseValidateAndLoad(key);
260+
}
257261
}
258262
};
259263

amplitude.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

documentation/Amplitude.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ <h4 class="name" id="__VERSION__"><span class="type-signature"></span>__VERSION_
184184

185185
<dt class="tag-source">Source:</dt>
186186
<dd class="tag-source"><ul class="dummy"><li>
187-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line1006">line 1006</a>
187+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line1010">line 1010</a>
188188
</li></ul></dd>
189189

190190

@@ -267,7 +267,7 @@ <h4 class="name" id="clearUserProperties"><span class="type-signature"></span>cl
267267

268268
<dt class="tag-source">Source:</dt>
269269
<dd class="tag-source"><ul class="dummy"><li>
270-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line618">line 618</a>
270+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line622">line 622</a>
271271
</li></ul></dd>
272272

273273

@@ -354,7 +354,7 @@ <h4 class="name" id="getSessionId"><span class="type-signature"></span>getSessio
354354

355355
<dt class="tag-source">Source:</dt>
356356
<dd class="tag-source"><ul class="dummy"><li>
357-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line216">line 216</a>
357+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line220">line 220</a>
358358
</li></ul></dd>
359359

360360

@@ -533,7 +533,7 @@ <h5>Parameters:</h5>
533533

534534
<dt class="tag-source">Source:</dt>
535535
<dd class="tag-source"><ul class="dummy"><li>
536-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line639">line 639</a>
536+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line643">line 643</a>
537537
</li></ul></dd>
538538

539539

@@ -828,7 +828,7 @@ <h4 class="name" id="isNewSession"><span class="type-signature"></span>isNewSess
828828

829829
<dt class="tag-source">Source:</dt>
830830
<dd class="tag-source"><ul class="dummy"><li>
831-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line207">line 207</a>
831+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line211">line 211</a>
832832
</li></ul></dd>
833833

834834

@@ -1028,7 +1028,7 @@ <h5>Parameters:</h5>
10281028

10291029
<dt class="tag-source">Source:</dt>
10301030
<dd class="tag-source"><ul class="dummy"><li>
1031-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line791">line 791</a>
1031+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line795">line 795</a>
10321032
</li></ul></dd>
10331033

10341034

@@ -1210,7 +1210,7 @@ <h5>Parameters:</h5>
12101210

12111211
<dt class="tag-source">Source:</dt>
12121212
<dd class="tag-source"><ul class="dummy"><li>
1213-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line818">line 818</a>
1213+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line822">line 822</a>
12141214
</li></ul></dd>
12151215

12161216

@@ -1348,7 +1348,7 @@ <h5>Parameters:</h5>
13481348

13491349
<dt class="tag-source">Source:</dt>
13501350
<dd class="tag-source"><ul class="dummy"><li>
1351-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line576">line 576</a>
1351+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line580">line 580</a>
13521352
</li></ul></dd>
13531353

13541354

@@ -1484,7 +1484,7 @@ <h5>Parameters:</h5>
14841484

14851485
<dt class="tag-source">Source:</dt>
14861486
<dd class="tag-source"><ul class="dummy"><li>
1487-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line517">line 517</a>
1487+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line521">line 521</a>
14881488
</li></ul></dd>
14891489

14901490

@@ -1573,7 +1573,7 @@ <h4 class="name" id="setGlobalUserProperties"><span class="type-signature"></spa
15731573

15741574
<dt class="tag-source">Source:</dt>
15751575
<dd class="tag-source"><ul class="dummy"><li>
1576-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line996">line 996</a>
1576+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line1000">line 1000</a>
15771577
</li></ul></dd>
15781578

15791579

@@ -1704,7 +1704,7 @@ <h5>Parameters:</h5>
17041704

17051705
<dt class="tag-source">Source:</dt>
17061706
<dd class="tag-source"><ul class="dummy"><li>
1707-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line555">line 555</a>
1707+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line559">line 559</a>
17081708
</li></ul></dd>
17091709

17101710

@@ -1835,7 +1835,7 @@ <h5>Parameters:</h5>
18351835

18361836
<dt class="tag-source">Source:</dt>
18371837
<dd class="tag-source"><ul class="dummy"><li>
1838-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line540">line 540</a>
1838+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line544">line 544</a>
18391839
</li></ul></dd>
18401840

18411841

@@ -1995,7 +1995,7 @@ <h5>Parameters:</h5>
19951995

19961996
<dt class="tag-source">Source:</dt>
19971997
<dd class="tag-source"><ul class="dummy"><li>
1998-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line599">line 599</a>
1998+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line603">line 603</a>
19991999
</li></ul></dd>
20002000

20012001

@@ -2131,7 +2131,7 @@ <h5>Parameters:</h5>
21312131

21322132
<dt class="tag-source">Source:</dt>
21332133
<dd class="tag-source"><ul class="dummy"><li>
2134-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line679">line 679</a>
2134+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line683">line 683</a>
21352135
</li></ul></dd>
21362136

21372137

@@ -2297,7 +2297,7 @@ <h5>Parameters:</h5>
22972297

22982298
<dt class="tag-source">Source:</dt>
22992299
<dd class="tag-source"><ul class="dummy"><li>
2300-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line774">line 774</a>
2300+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line778">line 778</a>
23012301
</li></ul></dd>
23022302

23032303

@@ -2343,7 +2343,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
23432343
<br class="clear">
23442344

23452345
<footer>
2346-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 05 2016 00:06:12 GMT-0700 (PDT)
2346+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 05 2016 13:49:39 GMT-0700 (PDT)
23472347
</footer>
23482348

23492349
<script> prettyPrint(); </script>

documentation/Identify.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
12951295
<br class="clear">
12961296

12971297
<footer>
1298-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 05 2016 00:06:12 GMT-0700 (PDT)
1298+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 05 2016 13:49:40 GMT-0700 (PDT)
12991299
</footer>
13001300

13011301
<script> prettyPrint(); </script>

documentation/amplitude.js.html

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,14 @@ <h1 class="page-title">Source: amplitude.js</h1>
158158
}
159159

160160
// validates config value is defined, is the correct type, and some additional value sanity checks
161-
var parseValidateLoad = function parseValidateLoad(key, expectedType) {
161+
var parseValidateAndLoad = function parseValidateAndLoad(key) {
162+
if (!DEFAULT_OPTIONS.hasOwnProperty(key)) {
163+
return; // skip bogus config values
164+
}
165+
162166
var inputValue = config[key];
163-
if (inputValue === undefined || !utils.validateInput(inputValue, key + ' option', expectedType)) {
167+
var expectedType = type(DEFAULT_OPTIONS[key]);
168+
if (!utils.validateInput(inputValue, key + ' option', expectedType)) {
164169
return;
165170
}
166171
if (expectedType === 'boolean') {
@@ -171,11 +176,10 @@ <h1 class="page-title">Source: amplitude.js</h1>
171176
}
172177
};
173178

174-
// the DEFAULT_OPTIONS object defines all valid keys, and provides expected types for the value
175-
for (var key in DEFAULT_OPTIONS) {
176-
if (DEFAULT_OPTIONS.hasOwnProperty(key)) {
177-
parseValidateLoad(key, type(DEFAULT_OPTIONS[key]));
178-
}
179+
for (var key in config) {
180+
if (config.hasOwnProperty(key)) {
181+
parseValidateAndLoad(key);
182+
}
179183
}
180184
};
181185

@@ -1050,7 +1054,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
10501054
<br class="clear">
10511055

10521056
<footer>
1053-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 05 2016 00:06:12 GMT-0700 (PDT)
1057+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 05 2016 13:49:39 GMT-0700 (PDT)
10541058
</footer>
10551059

10561060
<script> prettyPrint(); </script>

documentation/identify.js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
226226
<br class="clear">
227227

228228
<footer>
229-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 05 2016 00:06:12 GMT-0700 (PDT)
229+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 05 2016 13:49:39 GMT-0700 (PDT)
230230
</footer>
231231

232232
<script> prettyPrint(); </script>

documentation/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
5656
<br class="clear">
5757

5858
<footer>
59-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 05 2016 00:06:12 GMT-0700 (PDT)
59+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 05 2016 13:49:39 GMT-0700 (PDT)
6060
</footer>
6161

6262
<script> prettyPrint(); </script>

src/amplitude.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,14 @@ var _parseConfig = function _parseConfig(options, config) {
130130
}
131131

132132
// validates config value is defined, is the correct type, and some additional value sanity checks
133-
var parseValidateLoad = function parseValidateLoad(key, expectedType) {
133+
var parseValidateAndLoad = function parseValidateAndLoad(key) {
134+
if (!DEFAULT_OPTIONS.hasOwnProperty(key)) {
135+
return; // skip bogus config values
136+
}
137+
134138
var inputValue = config[key];
135-
if (inputValue === undefined || !utils.validateInput(inputValue, key + ' option', expectedType)) {
139+
var expectedType = type(DEFAULT_OPTIONS[key]);
140+
if (!utils.validateInput(inputValue, key + ' option', expectedType)) {
136141
return;
137142
}
138143
if (expectedType === 'boolean') {
@@ -143,11 +148,10 @@ var _parseConfig = function _parseConfig(options, config) {
143148
}
144149
};
145150

146-
// the DEFAULT_OPTIONS object defines all valid keys, and provides expected types for the value
147-
for (var key in DEFAULT_OPTIONS) {
148-
if (DEFAULT_OPTIONS.hasOwnProperty(key)) {
149-
parseValidateLoad(key, type(DEFAULT_OPTIONS[key]));
150-
}
151+
for (var key in config) {
152+
if (config.hasOwnProperty(key)) {
153+
parseValidateAndLoad(key);
154+
}
151155
}
152156
};
153157

0 commit comments

Comments
 (0)