Skip to content

Commit

Permalink
optimize RegisterObject()
Browse files Browse the repository at this point in the history
  • Loading branch information
nkast committed Jul 19, 2022
1 parent 33d82d0 commit 571ea4b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Wasm.Dom/wwwroot/js/JSObject.6.0.1.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
window.nkJSObject =
{
objectMap: [],
emptySlots: [],
RegisterObject: function(obj)
{
if (obj == null)
return -1;
if (nkJSObject.objectMap.indexOf(obj) != -1)
throw "object already registered";

nkJSObject.objectMap.push(obj);
var uid = nkJSObject.objectMap.indexOf(obj);
return uid;
if (nkJSObject.emptySlots.length == 0)
{
nkJSObject.objectMap.push(obj);
var uid = nkJSObject.objectMap.lastIndexOf(obj);
return uid;
}
else
{
var uid = nkJSObject.emptySlots.pop();
nkJSObject.objectMap[uid] = obj;
return uid;
}
},
GetObject: function(uid)
{
Expand All @@ -19,6 +29,7 @@
DisposeObject: function(uid)
{
delete nkJSObject.objectMap[uid];
nkJSObject.emptySlots.push(uid);
},
GetWindow: function()
{
Expand Down

0 comments on commit 571ea4b

Please sign in to comment.