Skip to content

Commit

Permalink
Fix start and end pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBr committed Aug 4, 2018
1 parent 468b346 commit ab40019
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions core/src/main/java/org/jruby/RubyHash.java
Expand Up @@ -761,16 +761,7 @@ private final IRubyObject internalDeleteOpenAddressing(final int hash, final Ent
entries[(index * NUMBER_OF_ENTRIES) + 1] = null;
size--;

// move pointers in case we deleted first or last element
if (index == start && size > 0) {
start++;
while(entries[start * NUMBER_OF_ENTRIES] == null)
start++;
} else if (index == (end - 1) && (end - 1) > 0) {
end--;
while(entries[(end - 1) * NUMBER_OF_ENTRIES] == null && (end - 1) > 0)
end--;
}
updateStartAndEndPointer(index);
return otherValue;
}
}
Expand All @@ -796,16 +787,7 @@ private final IRubyObject internalDeleteLinearSearch(final int hash, final Entry
entries[(index * NUMBER_OF_ENTRIES) + 1] = null;
size--;

// move pointers in case we deleted first or last element
if (index == start && size > 0) {
start++;
while(entries[start * NUMBER_OF_ENTRIES] == null)
start++;
} else if (index == (end - 1) && (end - 1) > 0) {
end--;
while(entries[(end - 1) * NUMBER_OF_ENTRIES] == null && (end - 1) > 0)
end--;
}
updateStartAndEndPointer(index);
return otherValue;
}
}
Expand All @@ -814,6 +796,21 @@ private final IRubyObject internalDeleteLinearSearch(final int hash, final Entry
return null;
}

private final void updateStartAndEndPointer(final int index) {
if (size == 0) {
start = 0;
end = 0;
} else if (index == start) {
start++;
while(entries[start * NUMBER_OF_ENTRIES] == null)
start++;
} else if (index == (end - 1) && (end - 1) > 0) {
end--;
while(entries[(end - 1) * NUMBER_OF_ENTRIES] == null && (end - 1) > 0)
end--;
}
}

private final IRubyObject internalDelete(final int hash, final EntryMatchType matchType, final IRubyObject key, final IRubyObject value) {
if (size == 0) return null;
if (shouldSearchLinear()) {
Expand Down

0 comments on commit ab40019

Please sign in to comment.