diff src/org/tmatesoft/hg/internal/Pool.java @ 262:3dcd3dd90c77

Improve manifest parsing: decode bytes to chars once, minimize arraycopy on String instantiation, keep set of file revisions from previous manifest only
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 18 Aug 2011 03:46:36 +0200
parents e2115da4cf6a
children 6bb5e7ed051a
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/Pool.java	Wed Aug 17 20:30:06 2011 +0200
+++ b/src/org/tmatesoft/hg/internal/Pool.java	Thu Aug 18 03:46:36 2011 +0200
@@ -18,6 +18,8 @@
 
 import java.util.HashMap;
 
+import org.tmatesoft.hg.util.SparseSet;
+
 /**
  * Instance pooling.
  * 
@@ -25,7 +27,20 @@
  * @author TMate Software Ltd.
  */
 public class Pool<T> {
-	private final HashMap<T,T> unify = new HashMap<T, T>();
+	private final HashMap<T,T> unify;
+//	private final SparseSet<T> unify = new SparseSet<T>();
+	
+	public Pool() {
+		unify = new HashMap<T, T>();
+	}
+	
+	public Pool(int sizeHint) {
+		if (sizeHint <= 0) {
+			unify = new HashMap<T, T>();
+		} else {
+			unify = new HashMap<T, T>(sizeHint * 4 / 3, 0.75f);
+		}
+	}
 	
 	public T unify(T t) {
 		T rv = unify.get(t);
@@ -37,14 +52,30 @@
 		return rv;
 	}
 	
+	public boolean contains(T t) {
+		return unify.containsKey(t);
+	}
+	
+	public void record(T t) {
+		unify.put(t, t);
+	}
+	
+	public void clear() {
+		unify.clear();
+	}
+
+	public int size() {
+		return unify.size();
+	}
+
 	@Override
 	public String toString() {
 		StringBuilder sb = new StringBuilder();
 		sb.append(Pool.class.getSimpleName());
 		sb.append('<');
-		if (!unify.isEmpty()) {
-			sb.append(unify.keySet().iterator().next().getClass().getName());
-		}
+//		if (!unify.isEmpty()) {
+//			sb.append(unify.keySet().iterator().next().getClass().getName());
+//		}
 		sb.append('>');
 		sb.append(':');
 		sb.append(unify.size());