Skip to content

Commit

Permalink
Improved constructors for array-based maps
Browse files Browse the repository at this point in the history
  • Loading branch information
vigna committed May 20, 2020
1 parent a87ffe4 commit ea251f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
was allowing a load factor of 1. Thanks to Andy Clegg for
reporting this bug.

- The copy constructor of array-based maps are now more efficient.
Thanks to Vladimir Krivosheev for proposing this enhancement.

8.3.1

- Fixed old-standing bug in the remove() method of the key set of
Expand Down
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ javadoc.base=/usr/share/javadoc

build.sysclasspath=ignore

version=8.3.1
version=8.3.2

dist=dist
src=src
Expand Down
14 changes: 12 additions & 2 deletions drv/ArrayMap.drv
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC
*/
public ARRAY_MAP(final MAP KEY_VALUE_GENERIC m) {
this(m.size());
putAll(m);
int i = 0;
for(MAP.Entry KEY_VALUE_GENERIC e : m.ENTRYSET()) {
key[i] = e.ENTRY_GET_KEY();
value[i] = e.ENTRY_GET_VALUE();
i++;
}
}

/** Creates a new empty array map copying the entries of a given map.
Expand All @@ -88,7 +93,12 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC
*/
public ARRAY_MAP(final Map<? extends KEY_GENERIC_CLASS, ? extends VALUE_GENERIC_CLASS> m) {
this(m.size());
putAll(m);
int i = 0;
for(Map.Entry<? extends KEY_GENERIC_CLASS, ? extends VALUE_GENERIC_CLASS> e : m.entrySet()) {
key[i] = KEY_OBJ2TYPE(e.getKey());
value[i] = VALUE_OBJ2TYPE(e.getValue());
i++;
}
}

/** Creates a new array map with given key and value backing arrays, using the given number of elements.
Expand Down

0 comments on commit ea251f9

Please sign in to comment.