diff options
author | paltherr <paltherr@epfl.ch> | 2004-03-19 02:22:20 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2004-03-19 02:22:20 +0000 |
commit | 2cfc33e42c250dad51c645a610d2d8d138821a50 (patch) | |
tree | d39070a8e9212a0c9da521d965cafa2e530c83c5 | |
parent | a32de8bd0c06eb9e400f3a8cf6fe958f7bd337ce (diff) | |
download | scala-2cfc33e42c250dad51c645a610d2d8d138821a50.tar.gz scala-2cfc33e42c250dad51c645a610d2d8d138821a50.tar.bz2 scala-2cfc33e42c250dad51c645a610d2d8d138821a50.zip |
- Name.toAsciiUnsafe
-rw-r--r-- | sources/scalac/symtab/classfile/Pickle.java | 2 | ||||
-rw-r--r-- | sources/scalac/util/Name.java | 8 | ||||
-rw-r--r-- | sources/scalac/util/TermName.java | 35 |
3 files changed, 34 insertions, 11 deletions
diff --git a/sources/scalac/symtab/classfile/Pickle.java b/sources/scalac/symtab/classfile/Pickle.java index 1e355faca9..682d94ede9 100644 --- a/sources/scalac/symtab/classfile/Pickle.java +++ b/sources/scalac/symtab/classfile/Pickle.java @@ -304,7 +304,7 @@ public class Pickle implements Kinds, Modifiers, EntryTags { private void writeName(Name name) { writeByte(name.isTermName() ? TERMname : TYPEname); writeByte(0); // space for length - byte[] ascii = SourceRepresentation.string2ascii(name.toString()); + byte[] ascii = name.toAsciiUnsafe(); while (bp + ascii.length > bytes.length) resizeTo(bytes.length * 2); System.arraycopy(ascii, 0, bytes, bp, ascii.length); if (debug) System.out.print(name); diff --git a/sources/scalac/util/Name.java b/sources/scalac/util/Name.java index c6da6ad003..af088d6f79 100644 --- a/sources/scalac/util/Name.java +++ b/sources/scalac/util/Name.java @@ -121,5 +121,13 @@ public abstract class Name { return term.toString(); } + /** + * Returns the ASCII representation of this name. The returned + * array is not a copy. Therefore, it is forbidden to modify it. + */ + public byte[] toAsciiUnsafe() { + return term.toAsciiUnsafe(); + } + //######################################################################## } diff --git a/sources/scalac/util/TermName.java b/sources/scalac/util/TermName.java index be6b2511a8..8215a8ce2e 100644 --- a/sources/scalac/util/TermName.java +++ b/sources/scalac/util/TermName.java @@ -52,12 +52,11 @@ public final class TermName extends Name { int index = hashValue(bytes, start, count) & (asciis.length - 1); for (TermName name = asciis[index]; name != null; name = name.next) if (name.equals(bytes, start, count)) return name; - TermName name = fromString(toString(bytes, start, count)); - assert name.ascii == null: name; - byte[] ascii = name.ascii = new byte[count]; + TermName name = fromString( + SourceRepresentation.ascii2string(bytes, start, count)); + byte[] ascii = new byte[count]; for (int i = 0; i < ascii.length; i++) ascii[i] = bytes[start + i]; - name.next = asciis[index]; - asciis[index] = name; + name.setAscii(ascii, index); return name; } @@ -75,9 +74,30 @@ public final class TermName extends Name { return string; } + /** + * Returns the ASCII representation of this name. The returned + * array is not a copy. Therefore, it is forbidden to modify it. + */ + public byte[] toAsciiUnsafe() { + if (ascii == null) { + byte[] ascii = SourceRepresentation.string2ascii(string); + int index = hashValue(ascii, 0, ascii.length) & (asciis.length-1); + setAscii(ascii, index); + } + return ascii; + } + //######################################################################## // Private Methods & Functions + /** Sets the ASCII representation to given one. */ + private void setAscii(byte[] ascii, int index) { + assert this.ascii == null: this; + this.ascii = ascii; + this.next = asciis[index]; + asciis[index] = this; + } + /** Is this name's ASCII representations equal to given one? */ private boolean equals(byte[] bytes, int start, int count) { if (ascii.length != count) return false; @@ -95,10 +115,5 @@ public final class TermName extends Name { + bytes[start + (count >> 1)]; } - /** Turns the ASCII representation into a string. */ - private static String toString(byte[] bytes, int start, int count) { - return SourceRepresentation.ascii2string(bytes, start, count); - } - //######################################################################## } |