Skip to content

Optimizations + Object.keys bugfix #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions public/javascripts/core/collections/hash_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ thisModule.addSlots(avocado.hashTable, function(add) {
}, {category: ['accessing']});

add.method('_each', function (iterator) {
for (var h in this._buckets) {
if (this._buckets.hasOwnProperty(h)) {
var b = this._buckets[h];
if (b instanceof Array) {
for (var i = 0, n = b.length; i < n; ++i) {
var entry = b[i];
iterator(entry);
}
var keys = Object.native_keys(this._buckets);
var length = keys.length;
for (var i = 0; i < length; i++) {
var b = this._buckets[keys[i]];
if(b && b instanceof Array) {
for (var j = 0, n = b.length; j < n; ++j) {
var entry = b[j];
iterator(entry);
}
}
}
Expand Down
38 changes: 21 additions & 17 deletions public/javascripts/core/deep_copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,21 @@ thisModule.addSlots(avocado.deepCopier, function(add) {
var isArray = isObj && (o instanceof Array);
c = isObj ? (isArray ? [] : Object.create(o['__proto__'])) : eval("(" + o.toString() + ")");
var thisCopier = this;
for (var n in o) {
if (o.hasOwnProperty(n)) {
var contents = o[n];
if (n === '__annotation__') {
c[n] = contents.copy();
var keys = Object.native_keys(o);
var length = keys.length;
for (var j = 0; j < length; ++j){
var n = keys[j];
var contents = o[n];
if (n === '__annotation__') {
c[n] = contents.copy();
} else if (contents) {
var contentsType = typeof(contents);
var contentsCreatorSlot = (contentsType === 'object' || contentsType === 'function') && avocado.annotator.theCreatorSlotOf(contents);
if (contentsCreatorSlot && contentsCreatorSlot.name === n && contentsCreatorSlot.holder === o) {
c[n] = thisCopier.createCopyOf(contents);
avocado.annotator.annotationOf(c[n]).setCreatorSlot(n, c);
} else {
var contentsType = typeof(contents);
var contentsCreatorSlot = (contentsType === 'object' || contentsType === 'function') && avocado.annotator.theCreatorSlotOf(contents);
if (contentsCreatorSlot && contentsCreatorSlot.name === n && contentsCreatorSlot.holder === o) {
c[n] = thisCopier.createCopyOf(contents);
avocado.annotator.annotationOf(c[n]).setCreatorSlot(n, c);
} else {
c[n] = contents;
}
c[n] = contents;
}
}
}
Expand Down Expand Up @@ -87,12 +88,15 @@ thisModule.addSlots(avocado.deepCopier, function(add) {
var thisCopier = this;
var originalsAndCopies = this._originalsAndCopies;
var originalsAndCopiesCount = originalsAndCopies.length;
for (var n in c) {
if (c.hasOwnProperty(n)) {
var keys = Object.native_keys(c);
var length = keys.length;
for (var j = 0; j < length; ++j){
var n = keys[j];
var contents = c[n];
if (contents) {
if (n === '__annotation__') {
// just ignore it, no refs to fix up, I think - oh, actually, could do the creator slot, but we've already done it up above
} else {
var contents = c[n];
} else {
var contentsType = typeof(contents);
if (contentsType === 'object' || contentsType === 'function') {
var wasInternalRef = false;
Expand Down
18 changes: 11 additions & 7 deletions public/javascripts/lk/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Object.defineProperties = function(object, descriptorSet) {
}
return object;
}


Object.native_keys = Object.keys;
Object.defineProperties(Object, {
// I like mine better. -- Adam
/*
Expand All @@ -62,12 +63,15 @@ Object.defineProperties(Object, {
*/

keys: {
value: function(object, optFast) {
if (typeof object !== 'object') throw new TypeError('not an object');
var names = []; // check behavior wrt arrays
for (var name in object) {
if (object.hasOwnProperty(name))
names.push(name);
value: function(object, optFast) {
if (typeof object !== 'object' && typeof object !== 'function') throw new TypeError('not an object');
var names = []; // check behavior wrt arrays
var keys = Object.native_keys(object);
var length = keys.length;
for (var i = 0; i < length; ++i) {
var name = keys[i];
if (object[name])
names.push(name);
}
if (!optFast) names.sort();
return names;
Expand Down