소스 검색

Initialise VMap and HashMap values to the default when they are created.

Assigns a default value in VMap and HashMap when new keys are created using
the array operator so they are the same as the other Map classes.

The non const version of the array operator can be used for both assigning a
value and retrieving a writeable version. In the Map template classes the
assign version is being used to create new keys, but sometimes not assigning
a value when retrieving a writeable version.

This does not address the problem that the default value may not be the
correct one, and it does not address the problem that new keys probably
should not be created when the array operator is used. These problems will
be addressed in a separate commit.
Marcel Admiraal 5 년 전
부모
커밋
ce352ce5b4
2개의 변경된 파일2개의 추가작업 그리고 2개의 파일을 삭제
  1. 1 0
      core/hash_map.h
  2. 1 2
      core/vmap.h

+ 1 - 0
core/hash_map.h

@@ -210,6 +210,7 @@ private:
 		e->next = hash_table[index];
 		e->next = hash_table[index];
 		e->hash = hash;
 		e->hash = hash;
 		e->pair.key = p_key;
 		e->pair.key = p_key;
+		e->pair.data = TData();
 
 
 		hash_table[index] = e;
 		hash_table[index] = e;
 		elements++;
 		elements++;

+ 1 - 2
core/vmap.h

@@ -196,8 +196,7 @@ public:
 
 
 		int pos = _find_exact(p_key);
 		int pos = _find_exact(p_key);
 		if (pos < 0) {
 		if (pos < 0) {
-			V val;
-			pos = insert(p_key, val);
+			pos = insert(p_key, V());
 		}
 		}
 
 
 		return _cowdata.get_m(pos).value;
 		return _cowdata.get_m(pos).value;