switch Context._pickObjects to a Map

This commit is contained in:
Adam Beili 2025-09-24 19:15:54 +03:00
parent b04b59282d
commit dbd13b65f3
1 changed files with 12 additions and 6 deletions

View File

@ -356,7 +356,7 @@ function Context(canvas, options) {
this._vertexAttribDivisors.push(0);
}
this._pickObjects = {};
this._pickObjects = new Map();
this._nextPickColor = new Uint32Array(1);
/**
@ -1575,9 +1575,15 @@ Context.prototype.getObjectByPickColor = function (pickColor) {
Check.defined("pickColor", pickColor);
//>>includeEnd('debug');
return this._pickObjects[pickColor.toRgba()];
return this._pickObjects.get(pickColor.toRgba());
};
/**
*
* @param {Map} pickObjects
* @param {number} key
* @param {Color} color
*/
function PickId(pickObjects, key, color) {
this._pickObjects = pickObjects;
this.key = key;
@ -1587,16 +1593,16 @@ function PickId(pickObjects, key, color) {
Object.defineProperties(PickId.prototype, {
object: {
get: function () {
return this._pickObjects[this.key];
return this._pickObjects.get(this.key);
},
set: function (value) {
this._pickObjects[this.key] = value;
this._pickObjects.set(this.key, value);
},
},
});
PickId.prototype.destroy = function () {
delete this._pickObjects[this.key];
this._pickObjects.delete(this.key);
return undefined;
};
@ -1633,7 +1639,7 @@ Context.prototype.createPickId = function (object) {
throw new RuntimeError("Out of unique Pick IDs.");
}
this._pickObjects[key] = object;
this._pickObjects.set(key, object);
return new PickId(this._pickObjects, key, Color.fromRgba(key));
};