-
Enhancement
-
Resolution: Fixed
-
P5
-
19
-
b26
There is HashMap 'regularKeyCodesMap' in sun.awt.ExtendedKeyCodes class. It contains only non-null keys and values.
t means we can replace containsKey+get with get+null check. Or with single getOrDefault call.
It's clearer and a bit faster.
public static final int getExtendedKeyCodeForChar( int c ) {
int uc = Character.toUpperCase( c );
int lc = Character.toLowerCase( c );
if (regularKeyCodesMap.containsKey( c )) {
if(regularKeyCodesMap.containsKey(uc)) {
return regularKeyCodesMap.get( uc );
}
return regularKeyCodesMap.get( c );
}
uc += 0x01000000;
lc += 0x01000000;
if (extendedKeyCodesSet.contains( uc )) {
return uc;
}else if (extendedKeyCodesSet.contains( lc )) {
return lc;
}
return KeyEvent.VK_UNDEFINED;
}
t means we can replace containsKey+get with get+null check. Or with single getOrDefault call.
It's clearer and a bit faster.
public static final int getExtendedKeyCodeForChar( int c ) {
int uc = Character.toUpperCase( c );
int lc = Character.toLowerCase( c );
if (regularKeyCodesMap.containsKey( c )) {
if(regularKeyCodesMap.containsKey(uc)) {
return regularKeyCodesMap.get( uc );
}
return regularKeyCodesMap.get( c );
}
uc += 0x01000000;
lc += 0x01000000;
if (extendedKeyCodesSet.contains( uc )) {
return uc;
}else if (extendedKeyCodesSet.contains( lc )) {
return lc;
}
return KeyEvent.VK_UNDEFINED;
}