Small performance improvement involving String.intern(). Plus a
little bit of code cleanup.
This commit is contained in:
parent
e5a63df1c1
commit
fcb75c55eb
1 changed files with 43 additions and 26 deletions
|
@ -66,7 +66,7 @@ public class TibetanMachineWeb {
|
||||||
private static Set farRightSet = null;
|
private static Set farRightSet = null;
|
||||||
private static Map tibHash = new HashMap();
|
private static Map tibHash = new HashMap();
|
||||||
private static Map binduMap = new HashMap();
|
private static Map binduMap = new HashMap();
|
||||||
private static String[][] toHashKey = new String[11][95]; //note: 0 slot is not used
|
private static String[][] toHashKey = new String[11][95]; //note: toHashKey[0][..] is not used
|
||||||
private static DuffCode[][] TMtoTMW = new DuffCode[5][255-32];
|
private static DuffCode[][] TMtoTMW = new DuffCode[5][255-32];
|
||||||
private static String fileName = "tibwn.ini";
|
private static String fileName = "tibwn.ini";
|
||||||
private static final String DELIMITER = "~";
|
private static final String DELIMITER = "~";
|
||||||
|
@ -83,26 +83,28 @@ public class TibetanMachineWeb {
|
||||||
private static boolean hasAVowel;
|
private static boolean hasAVowel;
|
||||||
private static String aVowel;
|
private static String aVowel;
|
||||||
|
|
||||||
|
// We use .intern() explicitly here so the code is easier to
|
||||||
|
// understand, but all string literals are interned.
|
||||||
public static final String[] tmFontNames = {
|
public static final String[] tmFontNames = {
|
||||||
null,
|
null,
|
||||||
"TibetanMachine",
|
"TibetanMachine".intern(),
|
||||||
"TibetanMachineSkt1",
|
"TibetanMachineSkt1".intern(),
|
||||||
"TibetanMachineSkt2",
|
"TibetanMachineSkt2".intern(),
|
||||||
"TibetanMachineSkt3",
|
"TibetanMachineSkt3".intern(),
|
||||||
"TibetanMachineSkt4"
|
"TibetanMachineSkt4".intern()
|
||||||
};
|
};
|
||||||
public static final String[] tmwFontNames = {
|
public static final String[] tmwFontNames = {
|
||||||
null,
|
null,
|
||||||
"TibetanMachineWeb",
|
"TibetanMachineWeb".intern(),
|
||||||
"TibetanMachineWeb1",
|
"TibetanMachineWeb1".intern(),
|
||||||
"TibetanMachineWeb2",
|
"TibetanMachineWeb2".intern(),
|
||||||
"TibetanMachineWeb3",
|
"TibetanMachineWeb3".intern(),
|
||||||
"TibetanMachineWeb4",
|
"TibetanMachineWeb4".intern(),
|
||||||
"TibetanMachineWeb5",
|
"TibetanMachineWeb5".intern(),
|
||||||
"TibetanMachineWeb6",
|
"TibetanMachineWeb6".intern(),
|
||||||
"TibetanMachineWeb7",
|
"TibetanMachineWeb7".intern(),
|
||||||
"TibetanMachineWeb8",
|
"TibetanMachineWeb8".intern(),
|
||||||
"TibetanMachineWeb9"
|
"TibetanMachineWeb9".intern()
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* the Wylie for bindu/anusvara
|
* the Wylie for bindu/anusvara
|
||||||
|
@ -286,6 +288,12 @@ public class TibetanMachineWeb {
|
||||||
* @param path a path within the JAR containing this class file
|
* @param path a path within the JAR containing this class file
|
||||||
* @throws Error if that assumption does not hold */
|
* @throws Error if that assumption does not hold */
|
||||||
private static void readInFontFile(String path) {
|
private static void readInFontFile(String path) {
|
||||||
|
|
||||||
|
// Note that the TM and TMW fonts do not have hanging
|
||||||
|
// baselines. They have Roman baselines. Tony Duff said this
|
||||||
|
// is subtly necessary and that only an OpenType font can
|
||||||
|
// support baselines properly.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream is = TibetanMachineWeb.class.getResourceAsStream(path);
|
InputStream is = TibetanMachineWeb.class.getResourceAsStream(path);
|
||||||
if (null == is) {
|
if (null == is) {
|
||||||
|
@ -500,7 +508,7 @@ public class TibetanMachineWeb {
|
||||||
public static boolean setKeyboard(TibetanKeyboard kb) {
|
public static boolean setKeyboard(TibetanKeyboard kb) {
|
||||||
keyboard = kb;
|
keyboard = kb;
|
||||||
|
|
||||||
if (keyboard == null) { //wylie keyboard
|
if (currentKeyboardIsExtendedWylie()) { //wylie keyboard
|
||||||
hasDisambiguatingKey = true;
|
hasDisambiguatingKey = true;
|
||||||
disambiguating_key = WYLIE_DISAMBIGUATING_KEY;
|
disambiguating_key = WYLIE_DISAMBIGUATING_KEY;
|
||||||
hasSanskritStackingKey = true;
|
hasSanskritStackingKey = true;
|
||||||
|
@ -605,7 +613,7 @@ public static boolean isFormatting(char c) {
|
||||||
* false if not
|
* false if not
|
||||||
*/
|
*/
|
||||||
public static boolean isChar(String s) {
|
public static boolean isChar(String s) {
|
||||||
if (keyboard == null) {
|
if (currentKeyboardIsExtendedWylie()) {
|
||||||
if (charSet.contains(s))
|
if (charSet.contains(s))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
|
@ -640,7 +648,7 @@ public static boolean isWylieChar(String s) {
|
||||||
* keyboard, false if not
|
* keyboard, false if not
|
||||||
*/
|
*/
|
||||||
public static boolean isPunc(String s) {
|
public static boolean isPunc(String s) {
|
||||||
if (keyboard == null) {
|
if (currentKeyboardIsExtendedWylie()) {
|
||||||
if (puncSet.contains(s))
|
if (puncSet.contains(s))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
|
@ -675,7 +683,7 @@ public static boolean isWyliePunc(String s) {
|
||||||
* keyboard, false if not
|
* keyboard, false if not
|
||||||
*/
|
*/
|
||||||
public static boolean isVowel(String s) {
|
public static boolean isVowel(String s) {
|
||||||
if (keyboard == null) {
|
if (currentKeyboardIsExtendedWylie()) {
|
||||||
if (vowelSet.contains(s))
|
if (vowelSet.contains(s))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
|
@ -764,12 +772,18 @@ public static boolean isWylieFarRight(String s) {
|
||||||
* @see TibetanKeyboard
|
* @see TibetanKeyboard
|
||||||
*/
|
*/
|
||||||
public static String getWylieForChar(String s) {
|
public static String getWylieForChar(String s) {
|
||||||
if (keyboard == null)
|
if (currentKeyboardIsExtendedWylie())
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
return keyboard.getWylieForChar(s);
|
return keyboard.getWylieForChar(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns true iff the currently active keyboard is the
|
||||||
|
* built-in, extended Wylie keyboard. */
|
||||||
|
public static boolean currentKeyboardIsExtendedWylie() {
|
||||||
|
return (null == getKeyboard());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current keyboard, or, if the current keyboard is the
|
* Returns the current keyboard, or, if the current keyboard is the
|
||||||
* Extended Wylie keyboard, null. */
|
* Extended Wylie keyboard, null. */
|
||||||
|
@ -787,7 +801,7 @@ public static String getWylieForChar(String s) {
|
||||||
* @see TibetanKeyboard
|
* @see TibetanKeyboard
|
||||||
*/
|
*/
|
||||||
public static String getWylieForPunc(String s) {
|
public static String getWylieForPunc(String s) {
|
||||||
if (keyboard == null)
|
if (currentKeyboardIsExtendedWylie())
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
return keyboard.getWylieForPunc(s);
|
return keyboard.getWylieForPunc(s);
|
||||||
|
@ -803,7 +817,7 @@ public static String getWylieForPunc(String s) {
|
||||||
* @see TibetanKeyboard
|
* @see TibetanKeyboard
|
||||||
*/
|
*/
|
||||||
public static String getWylieForVowel(String s) {
|
public static String getWylieForVowel(String s) {
|
||||||
if (keyboard == null)
|
if (currentKeyboardIsExtendedWylie())
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
return keyboard.getWylieForVowel(s);
|
return keyboard.getWylieForVowel(s);
|
||||||
|
@ -906,8 +920,9 @@ private static DuffCode getTMtoTMW(int font, int code) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getTMFontNumber(String name) {
|
private static int getTMFontNumber(String name) {
|
||||||
|
String internedName = name.intern();
|
||||||
for (int i=1; i<tmFontNames.length; i++) {
|
for (int i=1; i<tmFontNames.length; i++) {
|
||||||
if (name.equals(tmFontNames[i]))
|
if (internedName == tmFontNames[i])
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -920,8 +935,10 @@ private static int getTMFontNumber(String name) {
|
||||||
* of the TibetanMachineWeb fonts, otherwise 0
|
* of the TibetanMachineWeb fonts, otherwise 0
|
||||||
*/
|
*/
|
||||||
public static int getTMWFontNumber(String name) {
|
public static int getTMWFontNumber(String name) {
|
||||||
|
String internedName = name.intern();
|
||||||
for (int i=1; i<tmwFontNames.length; i++) {
|
for (int i=1; i<tmwFontNames.length; i++) {
|
||||||
if (name.equals(tmwFontNames[i]))
|
// Thanks to interning, we can use == rather than .equals().
|
||||||
|
if (internedName == tmwFontNames[i])
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1010,7 +1027,7 @@ public static String getWylieForGlyph(DuffCode dc) {
|
||||||
* legal input, ("Sh" + y) is not valid input for any non-empty
|
* legal input, ("Sh" + y) is not valid input for any non-empty
|
||||||
* String y. */
|
* String y. */
|
||||||
public static boolean hasInputPrefix(String s) {
|
public static boolean hasInputPrefix(String s) {
|
||||||
if (null != keyboard) {
|
if (!currentKeyboardIsExtendedWylie()) {
|
||||||
return keyboard.hasInputPrefix(s);
|
return keyboard.hasInputPrefix(s);
|
||||||
} else {
|
} else {
|
||||||
return validInputSequences.hasPrefix(s);
|
return validInputSequences.hasPrefix(s);
|
||||||
|
|
Loading…
Reference in a new issue