Add comment about ideally not relying on parent.children.indexOf for getIndex().

This commit is contained in:
Jürg Lehni 2011-02-13 18:51:49 +00:00
parent eeb7d377e6
commit 604ff7824c

View file

@ -1,5 +1,6 @@
Item = Base.extend({ Item = Base.extend({
beans: true, beans: true,
initialize: function() { initialize: function() {
this.parent = Paper.document.activeLayer; this.parent = Paper.document.activeLayer;
this.parent.children.push(this); this.parent.children.push(this);
@ -155,7 +156,7 @@ Item = Base.extend({
getNextSibling: function() { getNextSibling: function() {
if (this.parent) { if (this.parent) {
var index = this.index + 1; var index = this.index + 1;
if (index < this.parent.children.length) if (index < this.parent.children.length)
return this.parent.children[index]; return this.parent.children[index];
} }
}, },
@ -175,6 +176,9 @@ Item = Base.extend({
* The index of this item within the list of it's parent's children. * The index of this item within the list of it's parent's children.
*/ */
getIndex: function() { getIndex: function() {
// TODO: Relying on indexOf() here is slow, especially since it is
// used for getPrevious/NextSibling().
// We need linked lists instead.
return this.parent.children.indexOf(this); return this.parent.children.indexOf(this);
}, },