Skip to content

Commit 0db6ab2

Browse files
committed
perf: Switch to more native functions
1 parent 6200229 commit 0db6ab2

File tree

11 files changed

+45
-49
lines changed

11 files changed

+45
-49
lines changed

examples/annotations/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ function handleAnnotationChange(evt) {
356356
}
357357
var id = entry.attr('annotation-id');
358358
// Remove deleted annotations
359-
if ($.inArray(id, ids) < 0) {
359+
if (!ids.includes(id)) {
360360
entry.remove();
361361
return;
362362
}
@@ -366,7 +366,7 @@ function handleAnnotationChange(evt) {
366366
});
367367
// Add if new and fully created
368368
$.each(ids, function (idx, id) {
369-
if ($.inArray(id, present) >= 0) {
369+
if (present.includes(id)) {
370370
return;
371371
}
372372
var annotation = layer.annotationById(id);

examples/measure/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ function handleAnnotationChange(evt) {
541541
}
542542
var id = entry.attr('annotation-id');
543543
// Remove deleted annotations
544-
if ($.inArray(id, ids) < 0) {
544+
if (!ids.includes(id)) {
545545
entry.remove();
546546
return;
547547
}
@@ -562,7 +562,7 @@ function handleAnnotationChange(evt) {
562562
if (area) {
563563
dist = (dist ? dist + ' - ' : '') + area;
564564
}
565-
if ($.inArray(id, present) >= 0) {
565+
if (present.includes(id)) {
566566
$('#annotationlist .entry[annotation-id="' + id + '"] .entry-dist').text(dist);
567567
return;
568568
}

src/annotationLayer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ var annotationLayer = function (arg) {
536536
*/
537537
this.removeAnnotation = function (annotation, update, pos) {
538538
if (annotation.id && m_annotationIds[annotation.id()] !== undefined) {
539-
pos = $.inArray(annotation, m_annotations);
539+
pos = m_annotations.indexOf(annotation);
540540
if (annotation === m_this.currentAnnotation) {
541541
m_this.currentAnnotation = null;
542542
}
@@ -815,7 +815,7 @@ var annotationLayer = function (arg) {
815815
var type = (data.properties || {}).annotationType || feature.featureType,
816816
options = Object.assign({}, data.properties || {}),
817817
position, datagcs, i, existing;
818-
if ($.inArray(type, annotationList) < 0) {
818+
if (!annotationList.includes(type)) {
819819
return;
820820
}
821821
options.style = options.style || {};

src/fetchQueue.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ var fetchQueue = function (options) {
144144
*/
145145
this.add = function (defer, callback, atEnd) {
146146
if (defer.__fetchQueue) {
147-
var pos = $.inArray(defer, m_this._queue);
147+
var pos = m_this._queue.indexOf(defer);
148148
if (pos >= 0) {
149149
// m_this._queue.splice(pos, 1);
150150
m_this._addToQueue(defer, atEnd, pos);
@@ -215,7 +215,7 @@ var fetchQueue = function (options) {
215215
* @returns {number} -1 if not in the queue, or the position in the queue.
216216
*/
217217
this.get = function (defer) {
218-
return $.inArray(defer, m_this._queue);
218+
return m_this._queue.indexOf(defer);
219219
};
220220

221221
/**
@@ -225,7 +225,7 @@ var fetchQueue = function (options) {
225225
* @returns {boolean} `true` if the object was removed.
226226
*/
227227
this.remove = function (defer) {
228-
var pos = $.inArray(defer, m_this._queue);
228+
var pos = m_this._queue.indexOf(defer);
229229
if (pos >= 0) {
230230
m_this._queue.splice(pos, 1);
231231
return true;

src/mapInteractor.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,8 +1598,7 @@ var mapInteractor = function (args) {
15981598
clearState();
15991599

16001600
// if momentum is enabled, start the action here
1601-
if (m_options.momentum.enabled &&
1602-
$.inArray(oldAction, m_options.momentum.actions) >= 0) {
1601+
if (m_options.momentum.enabled && m_options.momentum.actions.includes(oldAction)) {
16031602
var t = (new Date()).valueOf();
16041603
var dt = t - m_mouse.time + m_mouse.deltaTime;
16051604
if (t - m_mouse.time < m_options.momentum.stopTime) {

src/quadFeature.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ var quadFeature = function (arg) {
466466
prev_onload = image.onload;
467467
image.onload = function () {
468468
if (previewColor !== undefined) {
469-
if ($.inArray(quad, clrQuads) >= 0) {
470-
clrQuads.splice($.inArray(quad, clrQuads), 1);
469+
if (clrQuads.includes(quad)) {
470+
clrQuads.splice(clrQuads.indexOf(quad), 1);
471471
}
472472
delete quadinfo.clrquad;
473473
}
@@ -544,8 +544,8 @@ var quadFeature = function (arg) {
544544
prev_onload = video.onloadeddata;
545545
video.onloadeddata = function () {
546546
if (previewColor !== undefined) {
547-
if ($.inArray(quad, clrQuads) >= 0) {
548-
clrQuads.splice($.inArray(quad, clrQuads), 1);
547+
if (clrQuads.includes(quad)) {
548+
clrQuads.splice(clrQuads.indexOf(quad), 1);
549549
}
550550
delete quadinfo.clrquad;
551551
}

src/registry.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var $ = require('jquery');
21
var geo_action = require('./action');
32
var util = require('./util/common');
43

@@ -460,7 +459,7 @@ registry.featuresForAnnotations = function (annotationList) {
460459
features.push(feature);
461460
} else {
462461
annotationList[ann].forEach(function (state) {
463-
if ($.inArray(state, annotations[ann].features[feature]) >= 0) {
462+
if (annotations[ann].features[feature].includes(state)) {
464463
features.push(feature);
465464
}
466465
});

src/util/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ var util = {
464464
do {
465465
found = util.hasAction(actions, action, name, owner);
466466
if (found) {
467-
actions.splice($.inArray(found, actions), 1);
467+
actions.splice(actions.indexOf(found), 1);
468468
removed += 1;
469469
}
470470
} while (found);
@@ -1010,7 +1010,7 @@ var util = {
10101010
continue;
10111011
}
10121012
const copy = source[key];
1013-
if (copy && typeof copy === 'object' && copy && (copy.constructor === undefined || copy.constructor === Object || Array.isArray(copy))) {
1013+
if (copy && typeof copy === 'object' && (copy.constructor === Object || Array.isArray(copy))) {
10141014
let src = target[key];
10151015
if (!Array.isArray(copy)) {
10161016
if (typeof src !== 'object' || Array.isArray(src)) {

tests/cases/annotation.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
describe('geo.annotation', function () {
44
'use strict';
55

6-
var $ = require('jquery');
76
var geo = require('../test-utils').geo;
87
var createMap = require('../test-utils').createMap;
98
var destroyMap = require('../test-utils').destroyMap;
@@ -1716,22 +1715,22 @@ describe('geo.annotation', function () {
17161715
var newshapeCount = 0;
17171716
it('listAnnotations', function () {
17181717
var list = geo.listAnnotations();
1719-
expect($.inArray('rectangle', list) >= 0).toBe(true);
1720-
expect($.inArray('polygon', list) >= 0).toBe(true);
1721-
expect($.inArray('point', list) >= 0).toBe(true);
1722-
expect($.inArray('line', list) >= 0).toBe(true);
1723-
expect($.inArray('unknown', list) >= 0).toBe(false);
1718+
expect(list.includes('rectangle')).toBe(true);
1719+
expect(list.includes('polygon')).toBe(true);
1720+
expect(list.includes('point')).toBe(true);
1721+
expect(list.includes('line')).toBe(true);
1722+
expect(list.includes('unknown')).toBe(false);
17241723
});
17251724
it('registerAnnotation', function () {
17261725
var func = function () { newshapeCount += 1; return 'newshape return'; };
17271726
sinon.stub(console, 'warn').callsFake(function () {});
1728-
expect($.inArray('newshape', geo.listAnnotations()) >= 0).toBe(false);
1727+
expect(geo.listAnnotations().includes('newshape')).toBe(false);
17291728
expect(geo.registerAnnotation('newshape', func)).toBe(undefined);
1730-
expect($.inArray('newshape', geo.listAnnotations()) >= 0).toBe(true);
1729+
expect(geo.listAnnotations().includes('newshape')).toBe(true);
17311730
expect(console.warn.calledOnce).toBe(false);
17321731
expect(geo.registerAnnotation('newshape', func).func).toBe(func);
17331732
expect(console.warn.calledOnce).toBe(true);
1734-
expect($.inArray('newshape', geo.listAnnotations()) >= 0).toBe(true);
1733+
expect(geo.listAnnotations().includes('newshape')).toBe(true);
17351734
console.warn.restore();
17361735
});
17371736
it('createAnnotation', function () {
@@ -1745,29 +1744,29 @@ describe('geo.annotation', function () {
17451744
});
17461745
it('featuresForAnnotations', function () {
17471746
var features = geo.featuresForAnnotations(['polygon']);
1748-
expect($.inArray('polygon', features) >= 0).toBe(true);
1749-
expect($.inArray('line.basic', features) >= 0).toBe(true);
1750-
expect($.inArray('point', features) >= 0).toBe(false);
1747+
expect(features.includes('polygon')).toBe(true);
1748+
expect(features.includes('line.basic')).toBe(true);
1749+
expect(features.includes('point')).toBe(false);
17511750
features = geo.featuresForAnnotations({polygon: true});
1752-
expect($.inArray('polygon', features) >= 0).toBe(true);
1753-
expect($.inArray('line.basic', features) >= 0).toBe(true);
1754-
expect($.inArray('point', features) >= 0).toBe(false);
1751+
expect(features.includes('polygon')).toBe(true);
1752+
expect(features.includes('line.basic')).toBe(true);
1753+
expect(features.includes('point')).toBe(false);
17551754
features = geo.featuresForAnnotations({polygon: [geo.annotation.state.done]});
1756-
expect($.inArray('polygon', features) >= 0).toBe(true);
1757-
expect($.inArray('line.basic', features) >= 0).toBe(false);
1758-
expect($.inArray('point', features) >= 0).toBe(false);
1755+
expect(features.includes('polygon')).toBe(true);
1756+
expect(features.includes('line.basic')).toBe(false);
1757+
expect(features.includes('point')).toBe(false);
17591758
features = geo.featuresForAnnotations({polygon: [geo.annotation.state.done, geo.annotation.state.create]});
1760-
expect($.inArray('polygon', features) >= 0).toBe(true);
1761-
expect($.inArray('line.basic', features) >= 0).toBe(true);
1762-
expect($.inArray('point', features) >= 0).toBe(false);
1759+
expect(features.includes('polygon')).toBe(true);
1760+
expect(features.includes('line.basic')).toBe(true);
1761+
expect(features.includes('point')).toBe(false);
17631762
features = geo.featuresForAnnotations(['polygon', 'point']);
1764-
expect($.inArray('polygon', features) >= 0).toBe(true);
1765-
expect($.inArray('line.basic', features) >= 0).toBe(true);
1766-
expect($.inArray('point', features) >= 0).toBe(true);
1763+
expect(features.includes('polygon')).toBe(true);
1764+
expect(features.includes('line.basic')).toBe(true);
1765+
expect(features.includes('point')).toBe(true);
17671766
features = geo.featuresForAnnotations(['polygon', 'unknown']);
1768-
expect($.inArray('polygon', features) >= 0).toBe(true);
1769-
expect($.inArray('line.basic', features) >= 0).toBe(true);
1770-
expect($.inArray('point', features) >= 0).toBe(false);
1767+
expect(features.includes('polygon')).toBe(true);
1768+
expect(features.includes('line.basic')).toBe(true);
1769+
expect(features.includes('point')).toBe(false);
17711770
});
17721771
it('rendererForAnnotations', function () {
17731772
sinon.stub(console, 'warn').callsFake(function () {});

tests/cases/fetchQueue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ describe('geo.core.fetchQueue', function () {
204204
expect(q.get(dlist[qrefs[i][j] - 1])).toBe(j);
205205
}
206206
for (j = 0; j < dlist.length; j += 1) {
207-
expect(q.get(dlist[j])).toBe($.inArray(dlist[j].ref, qrefs[i]));
207+
expect(q.get(dlist[j])).toBe(qrefs[i].indexOf(dlist[j].ref));
208208
}
209209
}
210210

0 commit comments

Comments
 (0)