瀏覽代碼

use class as an underlying type for haxe.ds.HashMap to avoid dynamic lookup on static platforms.

also, inline the constructor so the object can be inlined.
Dan Korostelev 10 年之前
父節點
當前提交
669cb86860
共有 1 個文件被更改,包括 12 次插入3 次删除
  1. 12 3
      std/haxe/ds/HashMap.hx

+ 12 - 3
std/haxe/ds/HashMap.hx

@@ -21,9 +21,9 @@
  */
  */
 package haxe.ds;
 package haxe.ds;
 
 
-abstract HashMap<K:{ function hashCode():Int; }, V >({keys:IntMap<K>, values:IntMap<V>}) {
-	public function new() {
-		this = { keys:new IntMap(), values: new IntMap() };
+abstract HashMap<K:{ function hashCode():Int; }, V >(HashMapData<K,V>) {
+	public inline function new() {
+		this = new HashMapData();
 	}
 	}
 	public inline function set(k:K, v:V) {
 	public inline function set(k:K, v:V) {
 		this.keys.set(k.hashCode(), k);
 		this.keys.set(k.hashCode(), k);
@@ -45,4 +45,13 @@ abstract HashMap<K:{ function hashCode():Int; }, V >({keys:IntMap<K>, values:Int
 	public inline function iterator() {
 	public inline function iterator() {
 		return this.values.iterator();
 		return this.values.iterator();
 	}
 	}
+}
+
+private class HashMapData<K:{ function hashCode():Int; },V> {
+	public var keys:IntMap<K>;
+	public var values:IntMap<V>;
+	public inline function new() {
+		keys = new IntMap();
+		values = new IntMap();
+	}
 }
 }