Răsfoiți Sursa

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 ani în urmă
părinte
comite
669cb86860
1 a modificat fișierele cu 12 adăugiri și 3 ștergeri
  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();
+	}
 }