Skip to content

Commit a201215

Browse files
committed
Fix: isEmpty in ArrayList works incorrectly.
1 parent 903f3b4 commit a201215

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

source/hunt/collection/AbstractList.d

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,10 @@ abstract class AbstractList(E) : AbstractCollection!E, List!E {
256256
override size_t toHash() @trusted nothrow {
257257
size_t hashCode = 1;
258258
try {
259-
static if (is(E == class)) {
260-
foreach (E e; this)
259+
static if (is(E == class) || is(E == interface)) {
260+
foreach (E e; this) {
261261
hashCode = 31 * hashCode + (e is null ? 0 : (cast(Object) e).toHash());
262+
}
262263
} else {
263264
foreach (E e; this)
264265
hashCode = 31 * hashCode + hashOf(e);

source/hunt/collection/ArrayList.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class ArrayList(E) : AbstractList!E {
226226
* @return <tt>true</tt> if this list contains no elements
227227
*/
228228
override bool isEmpty() {
229-
return _array.length == 0;
229+
return _size == 0;
230230
}
231231

232232
/**

source/hunt/collection/Map.d

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,8 +1114,11 @@ abstract class AbstractMapEntry(K, V) : MapEntry!(K,V) {
11141114

11151115
alias opCmp = Object.opCmp;
11161116

1117-
11181117
override size_t toHash() @trusted nothrow {
1119-
return hashOf(key) ^ hashOf(value);
1118+
static if(is(V == interface)) {
1119+
return hashOf(key) ^ hashOf(cast(Object)value);
1120+
} else {
1121+
return hashOf(key) ^ hashOf(value);
1122+
}
11201123
}
11211124
}

0 commit comments

Comments
 (0)