| Index: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/MemberMap.java
|
| diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/MemberMap.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/MemberMap.java
|
| index 898781b676d532c8d80f0dd519ff93ba26c8f48c..7bf66c9b62c2f36afa4809660865e84b1bf1c454 100644
|
| --- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/MemberMap.java
|
| +++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/MemberMap.java
|
| @@ -15,26 +15,34 @@ package com.google.dart.engine.internal.resolver;
|
|
|
| import com.google.dart.engine.element.ExecutableElement;
|
|
|
| +import java.util.HashMap;
|
| +import java.util.Set;
|
| +
|
| /**
|
| * This class is used to replace uses of {@code HashMap<String, ExecutableElement>} which are not as
|
| * performant as this class.
|
| */
|
| public class MemberMap {
|
|
|
| - /**
|
| - * The current size of this map.
|
| - */
|
| - private int size = 0;
|
| +// /**
|
| +// * The current size of this map.
|
| +// */
|
| +// private int size = 0;
|
|
|
| - /**
|
| - * The array of keys.
|
| - */
|
| - private String[] keys;
|
| +// /**
|
| +// * The array of keys.
|
| +// */
|
| +// private String[] keys;
|
| +
|
| +// /**
|
| +// * The array of ExecutableElement values.
|
| +// */
|
| +// private ExecutableElement[] values;
|
|
|
| /**
|
| - * The array of ExecutableElement values.
|
| + * The key-value pairs stored in an {@link HashMap}.
|
| */
|
| - private ExecutableElement[] values;
|
| + private HashMap<String, ExecutableElement> hashMap;
|
|
|
| /**
|
| * Default constructor.
|
| @@ -49,19 +57,21 @@ public class MemberMap {
|
| * @param initialCapacity the initial capacity
|
| */
|
| public MemberMap(int initialCapacity) {
|
| - initArrays(initialCapacity);
|
| +// initArrays(initialCapacity);
|
| + hashMap = new HashMap<String, ExecutableElement>(initialCapacity);
|
| }
|
|
|
| /**
|
| * Copy constructor.
|
| */
|
| public MemberMap(MemberMap memberMap) {
|
| - initArrays(memberMap.size + 5);
|
| - for (int i = 0; i < memberMap.size; i++) {
|
| - keys[i] = memberMap.keys[i];
|
| - values[i] = memberMap.values[i];
|
| - }
|
| - size = memberMap.size;
|
| +// initArrays(memberMap.size + 5);
|
| +// for (int i = 0; i < memberMap.size; i++) {
|
| +// keys[i] = memberMap.keys[i];
|
| +// values[i] = memberMap.values[i];
|
| +// }
|
| +// size = memberMap.size;
|
| + hashMap = new HashMap<String, ExecutableElement>(memberMap.hashMap);
|
| }
|
|
|
| /**
|
| @@ -73,25 +83,17 @@ public class MemberMap {
|
| * map, {@code null} is returned
|
| */
|
| public ExecutableElement get(String key) {
|
| - for (int i = 0; i < size; i++) {
|
| - if (keys[i] != null && keys[i].equals(key)) {
|
| - return values[i];
|
| - }
|
| - }
|
| - return null;
|
| +// for (int i = 0; i < size; i++) {
|
| +// if (keys[i] != null && keys[i].equals(key)) {
|
| +// return values[i];
|
| +// }
|
| +// }
|
| +// return null;
|
| + return hashMap.get(key);
|
| }
|
|
|
| - /**
|
| - * Get and return the key at the specified location. If the key/value pair has been removed from
|
| - * the set, then {@code null} is returned.
|
| - *
|
| - * @param i some non-zero value less than size
|
| - * @return the key at the passed index
|
| - * @throw ArrayIndexOutOfBoundsException this exception is thrown if the passed index is less than
|
| - * zero or greater than or equal to the capacity of the arrays
|
| - */
|
| - public String getKey(int i) {
|
| - return keys[i];
|
| + public Set<String> getKeys() {
|
| + return hashMap.keySet();
|
| }
|
|
|
| /**
|
| @@ -100,7 +102,8 @@ public class MemberMap {
|
| * @return the size of the map.
|
| */
|
| public int getSize() {
|
| - return size;
|
| +// return size;
|
| + return hashMap.size();
|
| }
|
|
|
| /**
|
| @@ -112,8 +115,8 @@ public class MemberMap {
|
| * @throw ArrayIndexOutOfBoundsException this exception is thrown if the passed index is less than
|
| * zero or greater than or equal to the capacity of the arrays
|
| */
|
| - public ExecutableElement getValue(int i) {
|
| - return values[i];
|
| + public ExecutableElement getValue(String key) {
|
| + return hashMap.get(key);
|
| }
|
|
|
| /**
|
| @@ -125,32 +128,33 @@ public class MemberMap {
|
| */
|
| public void put(String key, ExecutableElement value) {
|
| // If we already have a value with this key, override the value
|
| - for (int i = 0; i < size; i++) {
|
| - if (keys[i] != null && keys[i].equals(key)) {
|
| - values[i] = value;
|
| - return;
|
| - }
|
| - }
|
| -
|
| - // If needed, double the size of our arrays and copy values over in both arrays
|
| - if (size == keys.length) {
|
| - int newArrayLength = size * 2;
|
| - String[] keys_new_array = new String[newArrayLength];
|
| - ExecutableElement[] values_new_array = new ExecutableElement[newArrayLength];
|
| - for (int i = 0; i < size; i++) {
|
| - keys_new_array[i] = keys[i];
|
| - }
|
| - for (int i = 0; i < size; i++) {
|
| - values_new_array[i] = values[i];
|
| - }
|
| - keys = keys_new_array;
|
| - values = values_new_array;
|
| - }
|
| -
|
| - // Put new value at end of array
|
| - keys[size] = key;
|
| - values[size] = value;
|
| - size++;
|
| +// for (int i = 0; i < size; i++) {
|
| +// if (keys[i] != null && keys[i].equals(key)) {
|
| +// values[i] = value;
|
| +// return;
|
| +// }
|
| +// }
|
| +//
|
| +// // If needed, double the size of our arrays and copy values over in both arrays
|
| +// if (size == keys.length) {
|
| +// int newArrayLength = size * 2;
|
| +// String[] keys_new_array = new String[newArrayLength];
|
| +// ExecutableElement[] values_new_array = new ExecutableElement[newArrayLength];
|
| +// for (int i = 0; i < size; i++) {
|
| +// keys_new_array[i] = keys[i];
|
| +// }
|
| +// for (int i = 0; i < size; i++) {
|
| +// values_new_array[i] = values[i];
|
| +// }
|
| +// keys = keys_new_array;
|
| +// values = values_new_array;
|
| +// }
|
| +//
|
| +// // Put new value at end of array
|
| +// keys[size] = key;
|
| +// values[size] = value;
|
| +// size++;
|
| + hashMap.put(key, value);
|
| }
|
|
|
| /**
|
| @@ -161,31 +165,22 @@ public class MemberMap {
|
| * @param key the key of the key/value pair to remove from the map
|
| */
|
| public void remove(String key) {
|
| - for (int i = 0; i < size; i++) {
|
| - if (keys[i].equals(key)) {
|
| - keys[i] = null;
|
| - values[i] = null;
|
| - return;
|
| - }
|
| - }
|
| +// for (int i = 0; i < size; i++) {
|
| +// if (keys[i].equals(key)) {
|
| +// keys[i] = null;
|
| +// values[i] = null;
|
| +// return;
|
| +// }
|
| +// }
|
| + hashMap.remove(key);
|
| }
|
|
|
| - /**
|
| - * Sets the ExecutableElement at the specified location.
|
| - *
|
| - * @param i some non-zero value less than size
|
| - * @param value the ExecutableElement value to store in the map
|
| - */
|
| - public void setValue(int i, ExecutableElement value) {
|
| - values[i] = value;
|
| - }
|
| -
|
| - /**
|
| - * Initializes {@link #keys} and {@link #values}.
|
| - */
|
| - private void initArrays(int initialCapacity) {
|
| - keys = new String[initialCapacity];
|
| - values = new ExecutableElement[initialCapacity];
|
| - }
|
| +// /**
|
| +// * Initializes {@link #keys} and {@link #values}.
|
| +// */
|
| +// private void initArrays(int initialCapacity) {
|
| +// keys = new String[initialCapacity];
|
| +// values = new ExecutableElement[initialCapacity];
|
| +// }
|
|
|
| }
|
|
|