1 /* |
1 /* |
2 * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
30 import java.util.*; |
30 import java.util.*; |
31 |
31 |
32 import com.sun.tools.javac.code.Symbol; |
32 import com.sun.tools.javac.code.Symbol; |
33 import com.sun.tools.javac.code.Symbol.*; |
33 import com.sun.tools.javac.code.Symbol.*; |
34 import com.sun.tools.javac.code.Type; |
34 import com.sun.tools.javac.code.Type; |
|
35 import com.sun.tools.javac.util.ArrayUtils; |
35 import com.sun.tools.javac.util.Assert; |
36 import com.sun.tools.javac.util.Assert; |
36 import com.sun.tools.javac.util.Filter; |
37 import com.sun.tools.javac.util.Filter; |
37 import com.sun.tools.javac.util.Name; |
38 import com.sun.tools.javac.util.Name; |
38 import com.sun.tools.javac.util.Names; |
39 import com.sun.tools.javac.util.Names; |
39 |
40 |
87 /** Remove everything from this pool. |
88 /** Remove everything from this pool. |
88 */ |
89 */ |
89 public void reset() { |
90 public void reset() { |
90 pp = 1; |
91 pp = 1; |
91 indices.clear(); |
92 indices.clear(); |
92 } |
|
93 |
|
94 /** Double pool buffer in size. |
|
95 */ |
|
96 private void doublePool() { |
|
97 Object[] newpool = new Object[pool.length * 2]; |
|
98 System.arraycopy(pool, 0, newpool, 0, pool.length); |
|
99 pool = newpool; |
|
100 } |
93 } |
101 |
94 |
102 /** Place an object in the pool, unless it is already there. |
95 /** Place an object in the pool, unless it is already there. |
103 * If object is a symbol also enter its owner unless the owner is a |
96 * If object is a symbol also enter its owner unless the owner is a |
104 * package. Return the object's index in the pool. |
97 * package. Return the object's index in the pool. |
112 Integer index = indices.get(value); |
105 Integer index = indices.get(value); |
113 if (index == null) { |
106 if (index == null) { |
114 // System.err.println("put " + value + " " + value.getClass());//DEBUG |
107 // System.err.println("put " + value + " " + value.getClass());//DEBUG |
115 index = pp; |
108 index = pp; |
116 indices.put(value, index); |
109 indices.put(value, index); |
117 if (pp == pool.length) doublePool(); |
110 pool = ArrayUtils.ensureCapacity(pool, pp); |
118 pool[pp++] = value; |
111 pool[pp++] = value; |
119 if (value instanceof Long || value instanceof Double) { |
112 if (value instanceof Long || value instanceof Double) { |
120 if (pp == pool.length) doublePool(); |
113 pool = ArrayUtils.ensureCapacity(pool, pp); |
121 pool[pp++] = null; |
114 pool[pp++] = null; |
122 } |
115 } |
123 } |
116 } |
124 return index.intValue(); |
117 return index.intValue(); |
125 } |
118 } |