Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/Pool.java @ 195:c9b305df0b89
Optimization: use ParentWalker to get changeset's parents, if possible. Do not keep duplicating nodeids and strings in manifest revisions
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Fri, 15 Apr 2011 05:17:44 +0200 |
| parents | |
| children | e2115da4cf6a |
comparison
equal
deleted
inserted
replaced
| 194:344e8d7e4d6e | 195:c9b305df0b89 |
|---|---|
| 1 /* | |
| 2 * Copyright (c) 2011 TMate Software Ltd | |
| 3 * | |
| 4 * This program is free software; you can redistribute it and/or modify | |
| 5 * it under the terms of the GNU General Public License as published by | |
| 6 * the Free Software Foundation; version 2 of the License. | |
| 7 * | |
| 8 * This program is distributed in the hope that it will be useful, | |
| 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11 * GNU General Public License for more details. | |
| 12 * | |
| 13 * For information on how to redistribute this software under | |
| 14 * the terms of a license other than GNU General Public License | |
| 15 * contact TMate Software at support@hg4j.com | |
| 16 */ | |
| 17 package org.tmatesoft.hg.internal; | |
| 18 | |
| 19 import java.util.HashMap; | |
| 20 | |
| 21 /** | |
| 22 * Instance pooling. | |
| 23 * | |
| 24 * @author Artem Tikhomirov | |
| 25 * @author TMate Software Ltd. | |
| 26 */ | |
| 27 public class Pool<T> { | |
| 28 private final HashMap<T,T> unify = new HashMap<T, T>(); | |
| 29 | |
| 30 public T unify(T t) { | |
| 31 T rv = unify.get(t); | |
| 32 if (rv == null) { | |
| 33 // first time we see a new value | |
| 34 unify.put(t, t); | |
| 35 rv = t; | |
| 36 } | |
| 37 return rv; | |
| 38 } | |
| 39 } |
