author | jlahoda |
Wed, 27 Aug 2014 07:44:00 +0200 | |
changeset 26266 | 2d24bda701dc |
parent 25874 | 83c19f00452c |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
13844 | 2 |
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.util; |
|
27 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
28 |
import com.sun.tools.javac.util.DefinedBy.Api; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
29 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
30 |
/** An abstraction for internal compiler strings. They are stored in |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
31 |
* Utf8 format. Names are stored in a Name.Table, and are unique within |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
32 |
* that table. |
10 | 33 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
34 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
35 |
* If you write code that depends on this, you do so at your own risk. |
10 | 36 |
* This code and its internal interfaces are subject to change or |
37 |
* deletion without notice.</b> |
|
38 |
*/ |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
39 |
public abstract class Name implements javax.lang.model.element.Name { |
10 | 40 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
41 |
public final Table table; |
10 | 42 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
43 |
protected Name(Table table) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
44 |
this.table = table; |
10 | 45 |
} |
46 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
47 |
/** |
13844 | 48 |
* {@inheritDoc} |
10 | 49 |
*/ |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
50 |
@DefinedBy(Api.LANGUAGE_MODEL) |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
51 |
public boolean contentEquals(CharSequence cs) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
52 |
return toString().equals(cs.toString()); |
10 | 53 |
} |
54 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
55 |
/** |
13844 | 56 |
* {@inheritDoc} |
10 | 57 |
*/ |
58 |
public int length() { |
|
59 |
return toString().length(); |
|
60 |
} |
|
61 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
62 |
/** |
13844 | 63 |
* {@inheritDoc} |
10 | 64 |
*/ |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
65 |
public char charAt(int index) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
66 |
return toString().charAt(index); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
67 |
} |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
68 |
|
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
69 |
/** |
13844 | 70 |
* {@inheritDoc} |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
71 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
72 |
public CharSequence subSequence(int start, int end) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
73 |
return toString().subSequence(start, end); |
10 | 74 |
} |
75 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
76 |
/** Return the concatenation of this name and name `n'. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
77 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
78 |
public Name append(Name n) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
79 |
int len = getByteLength(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
80 |
byte[] bs = new byte[len + n.getByteLength()]; |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
81 |
getBytes(bs, 0); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
82 |
n.getBytes(bs, len); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
83 |
return table.fromUtf(bs, 0, bs.length); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
84 |
} |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
85 |
|
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
86 |
/** Return the concatenation of this name, the given ASCII |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
87 |
* character, and name `n'. |
10 | 88 |
*/ |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
89 |
public Name append(char c, Name n) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
90 |
int len = getByteLength(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
91 |
byte[] bs = new byte[len + 1 + n.getByteLength()]; |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
92 |
getBytes(bs, 0); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
93 |
bs[len] = (byte) c; |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
94 |
n.getBytes(bs, len+1); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
95 |
return table.fromUtf(bs, 0, bs.length); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
96 |
} |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
97 |
|
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
98 |
/** An arbitrary but consistent complete order among all Names. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
99 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
100 |
public int compareTo(Name other) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
101 |
return other.getIndex() - this.getIndex(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
102 |
} |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
103 |
|
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
104 |
/** Return true if this is the empty name. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
105 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
106 |
public boolean isEmpty() { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
107 |
return getByteLength() == 0; |
10 | 108 |
} |
109 |
||
110 |
/** Returns last occurrence of byte b in this name, -1 if not found. |
|
111 |
*/ |
|
112 |
public int lastIndexOf(byte b) { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
113 |
byte[] bytes = getByteArray(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
114 |
int offset = getByteOffset(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
115 |
int i = getByteLength() - 1; |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
116 |
while (i >= 0 && bytes[offset + i] != b) i--; |
10 | 117 |
return i; |
118 |
} |
|
119 |
||
120 |
/** Does this name start with prefix? |
|
121 |
*/ |
|
122 |
public boolean startsWith(Name prefix) { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
123 |
byte[] thisBytes = this.getByteArray(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
124 |
int thisOffset = this.getByteOffset(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
125 |
int thisLength = this.getByteLength(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
126 |
byte[] prefixBytes = prefix.getByteArray(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
127 |
int prefixOffset = prefix.getByteOffset(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
128 |
int prefixLength = prefix.getByteLength(); |
10 | 129 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
130 |
int i = 0; |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
131 |
while (i < prefixLength && |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
132 |
i < thisLength && |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
133 |
thisBytes[thisOffset + i] == prefixBytes[prefixOffset + i]) |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
134 |
i++; |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
135 |
return i == prefixLength; |
10 | 136 |
} |
137 |
||
138 |
/** Returns the sub-name starting at position start, up to and |
|
139 |
* excluding position end. |
|
140 |
*/ |
|
141 |
public Name subName(int start, int end) { |
|
142 |
if (end < start) end = start; |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
143 |
return table.fromUtf(getByteArray(), getByteOffset() + start, end - start); |
10 | 144 |
} |
145 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
146 |
/** Return the string representation of this name. |
10 | 147 |
*/ |
13844 | 148 |
@Override |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
149 |
public String toString() { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
150 |
return Convert.utf2string(getByteArray(), getByteOffset(), getByteLength()); |
10 | 151 |
} |
152 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
153 |
/** Return the Utf8 representation of this name. |
10 | 154 |
*/ |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
155 |
public byte[] toUtf() { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
156 |
byte[] bs = new byte[getByteLength()]; |
10 | 157 |
getBytes(bs, 0); |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
158 |
return bs; |
10 | 159 |
} |
160 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
161 |
/* Get a "reasonably small" value that uniquely identifies this name |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
162 |
* within its name table. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
163 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
164 |
public abstract int getIndex(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
165 |
|
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
166 |
/** Get the length (in bytes) of this name. |
10 | 167 |
*/ |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
168 |
public abstract int getByteLength(); |
10 | 169 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
170 |
/** Returns i'th byte of this name. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
171 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
172 |
public abstract byte getByteAt(int i); |
10 | 173 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
174 |
/** Copy all bytes of this name to buffer cs, starting at start. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
175 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
176 |
public void getBytes(byte cs[], int start) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
177 |
System.arraycopy(getByteArray(), getByteOffset(), cs, start, getByteLength()); |
10 | 178 |
} |
179 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
180 |
/** Get the underlying byte array for this name. The contents of the |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
181 |
* array must not be modified. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
182 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
183 |
public abstract byte[] getByteArray(); |
10 | 184 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
185 |
/** Get the start offset of this name within its byte array. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
186 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
187 |
public abstract int getByteOffset(); |
10 | 188 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
189 |
/** An abstraction for the hash table used to create unique Name instances. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
190 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
191 |
public static abstract class Table { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
192 |
/** Standard name table. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
193 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
194 |
public final Names names; |
10 | 195 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
196 |
Table(Names names) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
197 |
this.names = names; |
10 | 198 |
} |
199 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
200 |
/** Get the name from the characters in cs[start..start+len-1]. |
10 | 201 |
*/ |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
202 |
public abstract Name fromChars(char[] cs, int start, int len); |
10 | 203 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
204 |
/** Get the name for the characters in string s. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
205 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
206 |
public Name fromString(String s) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
207 |
char[] cs = s.toCharArray(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
208 |
return fromChars(cs, 0, cs.length); |
10 | 209 |
} |
210 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
211 |
/** Get the name for the bytes in array cs. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
212 |
* Assume that bytes are in utf8 format. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
213 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
214 |
public Name fromUtf(byte[] cs) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
215 |
return fromUtf(cs, 0, cs.length); |
10 | 216 |
} |
217 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
218 |
/** get the name for the bytes in cs[start..start+len-1]. |
10 | 219 |
* Assume that bytes are in utf8 format. |
220 |
*/ |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
221 |
public abstract Name fromUtf(byte[] cs, int start, int len); |
10 | 222 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
223 |
/** Release any resources used by this table. |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
224 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
225 |
public abstract void dispose(); |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
226 |
|
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
227 |
/** The hashcode of a name. |
10 | 228 |
*/ |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
229 |
protected static int hashValue(byte bytes[], int offset, int length) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
230 |
int h = 0; |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
231 |
int off = offset; |
10 | 232 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
233 |
for (int i = 0; i < length; i++) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
234 |
h = (h << 5) - h + bytes[off++]; |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
235 |
} |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
236 |
return h; |
10 | 237 |
} |
238 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
239 |
/** Compare two subarrays |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
240 |
*/ |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
241 |
protected static boolean equals(byte[] bytes1, int offset1, |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
242 |
byte[] bytes2, int offset2, int length) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
243 |
int i = 0; |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
244 |
while (i < length && bytes1[offset1 + i] == bytes2[offset2 + i]) { |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
245 |
i++; |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
246 |
} |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
247 |
return i == length; |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
248 |
} |
10 | 249 |
} |
250 |
} |