JS lib: simplify DefaultPrimitiveHashSet.

This commit is contained in:
Zalim Bashorov
2014-10-16 00:13:57 +04:00
parent 6eaa6201f0
commit 98d62283c7
+3 -54
View File
@@ -746,7 +746,7 @@
/** @constructs */ /** @constructs */
function () { function () {
this.$size = 0; this.$size = 0;
this.map = {}; this.map = Object.create(null);
}, },
/** @lends {Kotlin.AbstractPrimitiveHashSet.prototype} */ /** @lends {Kotlin.AbstractPrimitiveHashSet.prototype} */
{ {
@@ -796,69 +796,18 @@
} }
}); });
var PROTO_NAME = "__proto__";
lazyInitClasses.DefaultPrimitiveHashSet = Kotlin.createClass( lazyInitClasses.DefaultPrimitiveHashSet = Kotlin.createClass(
function () { function () {
return [Kotlin.AbstractPrimitiveHashSet]; return [Kotlin.AbstractPrimitiveHashSet];
}, },
/** @constructs */ /** @constructs */
function () { function () {
var superClass = Kotlin.AbstractPrimitiveHashSet; Kotlin.AbstractPrimitiveHashSet.call(this);
superClass.call(this);
this.super = superClass.prototype;
this.containsProto = false;
}, },
/** @lends {Kotlin.DefaultPrimitiveHashSet.prototype} */ /** @lends {Kotlin.DefaultPrimitiveHashSet.prototype} */
{ {
contains_za3rmp$: function (key) {
var skey = String(key);
if (skey === PROTO_NAME) {
return this.containsProto;
}
return this.super.contains_za3rmp$.call(this, key);
},
add_za3rmp$: function (element) {
var skey = String(element);
if (skey === PROTO_NAME) {
var isNewElement = !this.containsProto;
if (isNewElement) {
this.containsProto = true;
this.$size++;
}
return isNewElement;
}
return this.super.add_za3rmp$.call(this, element);
},
remove_za3rmp$: function (element) {
var skey = String(element);
if (skey === PROTO_NAME) {
var contains = this.containsProto;
if (contains) {
this.containsProto = false;
this.$size++;
}
return contains;
}
return this.super.remove_za3rmp$.call(this, element);
},
clear: function () {
this.$size = 0;
this.containsProto = false;
this.map = {};
},
toArray: function () { toArray: function () {
var elements = Object.keys(this.map); return Object.keys(this.map);
return !this.containsProto ? elements : elements.concat(PROTO_NAME);
} }
}); });