Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New optimized CatalogMap.values() method that is faster than using an…

… iterator
  • Loading branch information...
commit f2659fd1592b041a375a8f480f3b3baa1d4a211d 1 parent 66a4bc6
@apavlo authored
Showing with 10 additions and 3 deletions.
  1. +10 −3 src/catgen/in/javasrc/CatalogMap.java
View
13 src/catgen/in/javasrc/CatalogMap.java
@@ -41,6 +41,7 @@
public final class CatalogMap<T extends CatalogType> implements Iterable<T>, Collection<T> {
TreeMap<String, T> m_items = new TreeMap<String, T>();
+ T m_fastArray[];
Class<T> m_cls;
Catalog m_catalog;
CatalogType m_parent;
@@ -145,13 +146,14 @@ public T get(int index) {
@SuppressWarnings("unchecked")
public T[] values() {
+ if (m_fastArray != null) return (m_fastArray);
int capacity = this.size();
- final T a[] =(T[])Array.newInstance(this.m_cls, capacity);
+ m_fastArray =(T[])Array.newInstance(this.m_cls, capacity);
int i = 0;
for (T t : m_items.values()) {
- a[i++] = t;
+ m_fastArray[i++] = t;
}
- return a;
+ return m_fastArray;
}
public int getSubTreeVersion() {
@@ -188,6 +190,7 @@ public T add(String name) {
e.getValue().m_relativeIndex = index++;
}
+ m_fastArray = null;
return x;
} catch (Exception ex) {
throw new RuntimeException(ex);
@@ -226,6 +229,8 @@ public boolean add(T x, boolean initialize) {
for (Entry<String, T> e : m_items.entrySet()) {
e.getValue().m_relativeIndex = index++;
}
+
+ m_fastArray = null;
return (true);
}
@@ -252,6 +257,8 @@ public boolean delete(String name) {
} catch (Exception ex) {
throw new RuntimeException(ex);
}
+
+ m_fastArray = null;
return (true);
}
Please sign in to comment.
Something went wrong with that request. Please try again.