Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/Pool.java @ 264:6bb5e7ed051a
Optimize memory usage (reduce number of objects instantiated) when pooling file names and nodeids during manifest parsing
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 19 Aug 2011 03:36:25 +0200 |
parents | 3dcd3dd90c77 |
children | 12f668401613 |
comparison
equal
deleted
inserted
replaced
263:31f67be94e71 | 264:6bb5e7ed051a |
---|---|
16 */ | 16 */ |
17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
18 | 18 |
19 import java.util.HashMap; | 19 import java.util.HashMap; |
20 | 20 |
21 import org.tmatesoft.hg.util.SparseSet; | |
22 | |
23 /** | 21 /** |
24 * Instance pooling. | 22 * Instance pooling. |
25 * | 23 * |
26 * @author Artem Tikhomirov | 24 * @author Artem Tikhomirov |
27 * @author TMate Software Ltd. | 25 * @author TMate Software Ltd. |
28 */ | 26 */ |
29 public class Pool<T> { | 27 public class Pool<T> { |
30 private final HashMap<T,T> unify; | 28 private final HashMap<T,T> unify; |
31 // private final SparseSet<T> unify = new SparseSet<T>(); | |
32 | 29 |
33 public Pool() { | 30 public Pool() { |
34 unify = new HashMap<T, T>(); | 31 unify = new HashMap<T, T>(); |
35 } | 32 } |
36 | 33 |
71 @Override | 68 @Override |
72 public String toString() { | 69 public String toString() { |
73 StringBuilder sb = new StringBuilder(); | 70 StringBuilder sb = new StringBuilder(); |
74 sb.append(Pool.class.getSimpleName()); | 71 sb.append(Pool.class.getSimpleName()); |
75 sb.append('<'); | 72 sb.append('<'); |
76 // if (!unify.isEmpty()) { | 73 if (!unify.isEmpty()) { |
77 // sb.append(unify.keySet().iterator().next().getClass().getName()); | 74 sb.append(unify.keySet().iterator().next().getClass().getName()); |
78 // } | 75 } |
79 sb.append('>'); | 76 sb.append('>'); |
80 sb.append(':'); | 77 sb.append(':'); |
81 sb.append(unify.size()); | 78 sb.append(unify.size()); |
82 return sb.toString(); | 79 return sb.toString(); |
83 } | 80 } |