Browse Source

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 năm trước cách đây
mục cha
commit
669cb86860
1 tập tin đã thay đổi với 12 bổ sung3 xóa
  1. 12 3
      std/haxe/ds/HashMap.hx

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

@@ -21,9 +21,9 @@
  */
 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) {
 		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() {
 		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();
+	}
 }