Avoid redundant HashMap.containsKey calls in ExtendedKeyCodes.getExtendedKeyCodeForChar

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P5
    • 19
    • Affects Version/s: 19
    • Component/s: client-libs
    • 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;
           }

            Assignee:
            Andrey Turbanov
            Reporter:
            Andrey Turbanov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: