StringTablepublic class StringTable extends Object There are two string-like data types in today's JDK:
1) zero-terminated, C-language, ASCII strings
2) Java Strings.
The former arise from:
(a) UTF encoding of Java class, method, field names and type
signatures, used for linkage
(b) UTF encoded forms of Java String constants, used as keys
for the intern-ing of said constants.
See the class AsciiStrings where these are manipulated
to achieve some sharing of runtime data structures.
In this, the StringTable class, we keep track of Java Strings, in
the form of StringConstant's.
We enter them in a Str2ID structure, which will be wanted
at runtime. And we assign layout of the runtime char[] data.
Much aliasing of data is possible, since this is read-only and
not usually zero-terminated. We won't do any of that, for now.
There is much potential here. |
Fields Summary |
---|
public jcc.Str2ID | stringHash | public Hashtable | htable | public StringBuffer | data | private int | aggregateSize | private int | stringIndex |
Methods Summary |
---|
public java.util.Enumeration | allStrings()
return htable.elements();
| public int | arrangeStringData()
/*
* Our initial guess is simply to concatenate all the data.
* Later, we can try to be cleverer.
*/
data = new StringBuffer( aggregateSize );
int curOffset = 0;
Enumeration s = allStrings();
while ( s.hasMoreElements() ){
StringConstant t = (StringConstant)s.nextElement();
t.unicodeOffset = curOffset;
data.append( t.str.string );
curOffset += t.str.string.length();
}
return curOffset;
| public void | intern(components.StringConstant s)
StringConstant t = (StringConstant)htable.get( s );
if ( t == null ){
htable.put( s, s );
stringHash.getID( s.str , s );
aggregateSize += s.str.string.length();
s.unicodeIndex = stringIndex++;
} else {
s.unicodeIndex = t.unicodeIndex;
}
| public int | internedStringCount() return stringIndex;
|
|