瀏覽代碼

Lua: Do the length adjustment in Array.remove in two steps to avoid triggering __index metamethod

Justin Donaldson 9 年之前
父節點
當前提交
a7a41d6aea
共有 1 個文件被更改,包括 7 次插入4 次删除
  1. 7 4
      std/lua/_std/Array.hx

+ 7 - 4
std/lua/_std/Array.hx

@@ -134,10 +134,13 @@ class Array<T> {
 				for (j in i...length-1){
 				for (j in i...length-1){
 					this[j] = this[j+1];
 					this[j] = this[j+1];
 				}
 				}
-				// We need to decrement the length variable,
-				// and set its value to null to avoid hanging on to a reference
-				// in the underlying lua table.
-				this[--length] = null;
+				// We need to decrement the length variable, and set its 
+				// value to null to avoid hanging on to a reference in the 
+				// underlying lua table.  
+				this[length-1] = null;
+				// Do this in two steps to avoid re-updating the __index metamethod
+				length--;
+
 				return true;
 				return true;
 			}
 			}
 		}
 		}