소스 검색

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){
 					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;
 			}
 		}