Bug 1254755 part.6 Reorder the members of WidgetKeyboardEvent for reducing its instance size r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 12 May 2016 19:18:36 +0900
changeset 336536 841672e8aaf121beec31b3168cac9cf4ba8f2112
parent 336535 c54083f23a0b0911279f2f9d8f5553fec8ad733e
child 336537 e31c7784e29be1e1ca8a581f4d32827fe3b4d6c1
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1254755
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1254755 part.6 Reorder the members of WidgetKeyboardEvent for reducing its instance size r=smaug For reducing the instance size of WidgetKeyboardEvent, this patch also explicitly defines the type of KeyNameIndex and CodeNameIndex. MozReview-Commit-ID: 8Iw2e8ZFOpe
widget/EventForwards.h
widget/TextEvents.h
widget/nsGUIEventIPC.h
--- a/widget/EventForwards.h
+++ b/widget/EventForwards.h
@@ -78,30 +78,32 @@ enum EventClassID : EventClassIDType
 
 const char* ToChar(EventClassID aEventClassID);
 
 typedef uint16_t Modifiers;
 
 #define NS_DEFINE_KEYNAME(aCPPName, aDOMKeyName) \
   KEY_NAME_INDEX_##aCPPName,
 
-enum KeyNameIndex
+typedef uint16_t KeyNameIndexType;
+enum KeyNameIndex : KeyNameIndexType
 {
 #include "mozilla/KeyNameList.h"
   // If a DOM keyboard event is synthesized by script, this is used.  Then,
   // specified key name should be stored and use it as .key value.
   KEY_NAME_INDEX_USE_STRING
 };
 
 #undef NS_DEFINE_KEYNAME
 
 #define NS_DEFINE_PHYSICAL_KEY_CODE_NAME(aCPPName, aDOMCodeName) \
   CODE_NAME_INDEX_##aCPPName,
 
-enum CodeNameIndex
+typedef uint8_t CodeNameIndexType;
+enum CodeNameIndex : CodeNameIndexType
 {
 #include "mozilla/PhysicalKeyCodeNameList.h"
   // If a DOM keyboard event is synthesized by script, this is used.  Then,
   // specified code name should be stored and use it as .code value.
   CODE_NAME_INDEX_USE_STRING
 };
 
 #undef NS_DEFINE_PHYSICAL_KEY_CODE_NAME
--- a/widget/TextEvents.h
+++ b/widget/TextEvents.h
@@ -97,63 +97,63 @@ struct ShortcutKeyCandidate
 class WidgetKeyboardEvent : public WidgetInputEvent
 {
 private:
   friend class dom::PBrowserParent;
   friend class dom::PBrowserChild;
 
 protected:
   WidgetKeyboardEvent()
-    : mKeyCode(0)
+    : mNativeKeyEvent(nullptr)
+    , mKeyCode(0)
     , mCharCode(0)
     , mPseudoCharCode(0)
     , mLocation(nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD)
+    , mAccessKeyForwardedToChild(false)
+    , mUniqueId(0)
+#ifdef XP_MACOSX
+    , mNativeModifierFlags(0)
+    , mNativeKeyCode(0)
+#endif // #ifdef XP_MACOSX
+    , mKeyNameIndex(mozilla::KEY_NAME_INDEX_Unidentified)
+    , mCodeNameIndex(CODE_NAME_INDEX_UNKNOWN)
+    , mInputMethodAppState(eNotHandled)
     , mIsChar(false)
     , mIsRepeat(false)
     , mIsComposing(false)
     , mIsReserved(false)
-    , mAccessKeyForwardedToChild(false)
-    , mKeyNameIndex(mozilla::KEY_NAME_INDEX_Unidentified)
-    , mCodeNameIndex(CODE_NAME_INDEX_UNKNOWN)
-    , mNativeKeyEvent(nullptr)
-    , mUniqueId(0)
-#ifdef XP_MACOSX
-    , mNativeKeyCode(0)
-    , mNativeModifierFlags(0)
-#endif
-    , mInputMethodAppState(eNotHandled)
     , mIsSynthesizedByTIP(false)
   {
   }
 
 public:
   virtual WidgetKeyboardEvent* AsKeyboardEvent() override { return this; }
 
   WidgetKeyboardEvent(bool aIsTrusted, EventMessage aMessage,
                       nsIWidget* aWidget,
                       EventClassID aEventClassID = eKeyboardEventClass)
     : WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID)
+    , mNativeKeyEvent(nullptr)
     , mKeyCode(0)
     , mCharCode(0)
     , mPseudoCharCode(0)
     , mLocation(nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD)
+    , mAccessKeyForwardedToChild(false)
+    , mUniqueId(0)
+#ifdef XP_MACOSX
+    , mNativeModifierFlags(0)
+    , mNativeKeyCode(0)
+#endif // #ifdef XP_MACOSX
+    , mKeyNameIndex(mozilla::KEY_NAME_INDEX_Unidentified)
+    , mCodeNameIndex(CODE_NAME_INDEX_UNKNOWN)
+    , mInputMethodAppState(eNotHandled)
     , mIsChar(false)
     , mIsRepeat(false)
     , mIsComposing(false)
     , mIsReserved(false)
-    , mAccessKeyForwardedToChild(false)
-    , mKeyNameIndex(mozilla::KEY_NAME_INDEX_Unidentified)
-    , mCodeNameIndex(CODE_NAME_INDEX_UNKNOWN)
-    , mNativeKeyEvent(nullptr)
-    , mUniqueId(0)
-#ifdef XP_MACOSX
-    , mNativeKeyCode(0)
-    , mNativeModifierFlags(0)
-#endif
-    , mInputMethodAppState(eNotHandled)
     , mIsSynthesizedByTIP(false)
   {
     // If this is a keyboard event on a plugin, it shouldn't fired on content.
     mFlags.mOnlySystemGroupDispatchInContent =
       mFlags.mNoCrossProcessBoundaryForwarding = IsKeyEventOnPlugin();
   }
 
   static bool IsKeyDownOrKeyDownOnPlugin(EventMessage aMessage)
@@ -188,88 +188,93 @@ public:
     // Not copying widget, it is a weak reference.
     WidgetKeyboardEvent* result =
       new WidgetKeyboardEvent(false, mMessage, nullptr);
     result->AssignKeyEventData(*this, true);
     result->mFlags = mFlags;
     return result;
   }
 
+  // OS translated Unicode chars which are used for accesskey and accelkey
+  // handling. The handlers will try from first character to last character.
+  nsTArray<AlternativeCharCode> mAlternativeCharCodes;
+  // DOM KeyboardEvent.key only when mKeyNameIndex is KEY_NAME_INDEX_USE_STRING.
+  nsString mKeyValue;
+  // DOM KeyboardEvent.code only when mCodeNameIndex is
+  // CODE_NAME_INDEX_USE_STRING.
+  nsString mCodeValue;
+
+#ifdef XP_MACOSX
+  // Values given by a native NSEvent, for use with Cocoa NPAPI plugins.
+  nsString mNativeCharacters;
+  nsString mNativeCharactersIgnoringModifiers;
+  // If this is non-empty, create a text event for plugins instead of a
+  // keyboard event.
+  nsString mPluginTextEventString;
+#endif // #ifdef XP_MACOSX
+
+  // OS-specific native event can optionally be preserved
+  void* mNativeKeyEvent;
   // A DOM keyCode value or 0.  If a keypress event whose mCharCode is 0, this
   // should be 0.
   uint32_t mKeyCode;
   // If the instance is a keypress event of a printable key, this is a UTF-16
   // value of the key.  Otherwise, 0.  This value must not be a control
   // character when some modifiers are active.  Then, this value should be an
   // unmodified value except Shift and AltGr.
   uint32_t mCharCode;
   // mPseudoCharCode is valid only when mMessage is an eKeyDown event.
   // This stores mCharCode value of keypress event which is fired with same
   // key value and same modifier state.
   uint32_t mPseudoCharCode;
   // One of nsIDOMKeyEvent::DOM_KEY_LOCATION_*
   uint32_t mLocation;
-  // OS translated Unicode chars which are used for accesskey and accelkey
-  // handling. The handlers will try from first character to last character.
-  nsTArray<AlternativeCharCode> mAlternativeCharCodes;
+  // True if accesskey handling was forwarded to the child via
+  // TabParent::HandleAccessKey. In this case, parent process menu access key
+  // handling should be delayed until it is determined that there exists no
+  // overriding access key in the content process.
+  bool mAccessKeyForwardedToChild;
+  // Unique id associated with a keydown / keypress event. Used in identifing
+  // keypress events for removal from async event dispatch queue in metrofx
+  // after preventDefault is called on keydown events. It's ok if this wraps
+  // over long periods.
+  uint32_t mUniqueId;
+
+#ifdef XP_MACOSX
+  // Values given by a native NSEvent, for use with Cocoa NPAPI plugins.
+  uint32_t mNativeModifierFlags;
+  uint16_t mNativeKeyCode;
+#endif // #ifdef XP_MACOSX
+
+  // DOM KeyboardEvent.key
+  KeyNameIndex mKeyNameIndex;
+  // DOM KeyboardEvent.code
+  CodeNameIndex mCodeNameIndex;
+  // Indicates that the event is being handled by input method app
+  typedef uint8_t InputMethodAppStateType;
+  enum InputMethodAppState : InputMethodAppStateType
+  {
+    eNotHandled, // not yet handled by intput method app
+    eHandling,   // being handled by intput method app
+    eHandled     // handled by input method app
+  };
+  InputMethodAppState mInputMethodAppState;
+
   // Indicates whether the event signifies a printable character
   bool mIsChar;
   // Indicates whether the event is generated by auto repeat or not.
   // if this is keyup event, always false.
   bool mIsRepeat;
   // Indicates whether the event is generated during IME (or deadkey)
   // composition.  This is initialized by EventStateManager.  So, key event
   // dispatchers don't need to initialize this.
   bool mIsComposing;
   // Indicates if the key combination is reserved by chrome.  This is set by
   // nsXBLWindowKeyHandler at capturing phase of the default event group.
   bool mIsReserved;
-  // True if accesskey handling was forwarded to the child via
-  // TabParent::HandleAccessKey. In this case, parent process menu access key
-  // handling should be delayed until it is determined that there exists no
-  // overriding access key in the content process.
-  bool mAccessKeyForwardedToChild;
-  // DOM KeyboardEvent.key
-  KeyNameIndex mKeyNameIndex;
-  // DOM KeyboardEvent.code
-  CodeNameIndex mCodeNameIndex;
-  // DOM KeyboardEvent.key only when mKeyNameIndex is KEY_NAME_INDEX_USE_STRING.
-  nsString mKeyValue;
-  // DOM KeyboardEvent.code only when mCodeNameIndex is
-  // CODE_NAME_INDEX_USE_STRING.
-  nsString mCodeValue;
-  // OS-specific native event can optionally be preserved
-  void* mNativeKeyEvent;
-  // Unique id associated with a keydown / keypress event. Used in identifing
-  // keypress events for removal from async event dispatch queue in metrofx
-  // after preventDefault is called on keydown events. It's ok if this wraps
-  // over long periods.
-  uint32_t mUniqueId;
-
-#ifdef XP_MACOSX
-  // Values given by a native NSEvent, for use with Cocoa NPAPI plugins.
-  uint16_t mNativeKeyCode;
-  uint32_t mNativeModifierFlags;
-  nsString mNativeCharacters;
-  nsString mNativeCharactersIgnoringModifiers;
-  // If this is non-empty, create a text event for plugins instead of a
-  // keyboard event.
-  nsString mPluginTextEventString;
-#endif
-
-  // Indicates that the event is being handled by input method app
-  typedef uint8_t InputMethodAppStateType;
-  enum InputMethodAppState : InputMethodAppStateType
-  {
-    eNotHandled, // not yet handled by intput method app
-    eHandling,   // being handled by intput method app
-    eHandled     // handled by input method app
-  };
-  InputMethodAppState mInputMethodAppState;
-
   // Indicates whether the event is synthesized from Text Input Processor
   // or an actual event from nsAppShell.
   bool mIsSynthesizedByTIP;
 
   // If the key should cause keypress events, this returns true.
   // Otherwise, false.
   bool ShouldCauseKeypressEvents() const;
 
--- a/widget/nsGUIEventIPC.h
+++ b/widget/nsGUIEventIPC.h
@@ -385,50 +385,52 @@ struct ParamTraits<mozilla::AlternativeC
 template<>
 struct ParamTraits<mozilla::WidgetKeyboardEvent>
 {
   typedef mozilla::WidgetKeyboardEvent paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     WriteParam(aMsg, static_cast<mozilla::WidgetInputEvent>(aParam));
-    WriteParam(aMsg, static_cast<uint32_t>(aParam.mKeyNameIndex));
-    WriteParam(aMsg, static_cast<uint32_t>(aParam.mCodeNameIndex));
+    WriteParam(aMsg,
+               static_cast<mozilla::KeyNameIndexType>(aParam.mKeyNameIndex));
+    WriteParam(aMsg,
+               static_cast<mozilla::CodeNameIndexType>(aParam.mCodeNameIndex));
     WriteParam(aMsg, aParam.mKeyValue);
     WriteParam(aMsg, aParam.mCodeValue);
     WriteParam(aMsg, aParam.mKeyCode);
     WriteParam(aMsg, aParam.mCharCode);
     WriteParam(aMsg, aParam.mPseudoCharCode);
     WriteParam(aMsg, aParam.mAlternativeCharCodes);
     WriteParam(aMsg, aParam.mIsChar);
     WriteParam(aMsg, aParam.mIsRepeat);
     WriteParam(aMsg, aParam.mIsReserved);
     WriteParam(aMsg, aParam.mAccessKeyForwardedToChild);
     WriteParam(aMsg, aParam.mLocation);
     WriteParam(aMsg, aParam.mUniqueId);
     WriteParam(aMsg, aParam.mIsSynthesizedByTIP);
     WriteParam(aMsg,
-               static_cast<mozilla::WidgetKeyboardEvent::InputMethodAppStateType>
+               static_cast<paramType::InputMethodAppStateType>
                  (aParam.mInputMethodAppState));
 #ifdef XP_MACOSX
     WriteParam(aMsg, aParam.mNativeKeyCode);
     WriteParam(aMsg, aParam.mNativeModifierFlags);
     WriteParam(aMsg, aParam.mNativeCharacters);
     WriteParam(aMsg, aParam.mNativeCharactersIgnoringModifiers);
     WriteParam(aMsg, aParam.mPluginTextEventString);
 #endif
     // An OS-specific native event might be attached in |mNativeKeyEvent|,  but
     // that cannot be copied across process boundaries.
   }
 
   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   {
-    uint32_t keyNameIndex = 0, codeNameIndex = 0;
-    mozilla::WidgetKeyboardEvent::InputMethodAppStateType
-      inputMethodAppState = 0;
+    mozilla::KeyNameIndexType keyNameIndex = 0;
+    mozilla::CodeNameIndexType codeNameIndex = 0;
+    paramType::InputMethodAppStateType inputMethodAppState = 0;
     if (ReadParam(aMsg, aIter,
                   static_cast<mozilla::WidgetInputEvent*>(aResult)) &&
         ReadParam(aMsg, aIter, &keyNameIndex) &&
         ReadParam(aMsg, aIter, &codeNameIndex) &&
         ReadParam(aMsg, aIter, &aResult->mKeyValue) &&
         ReadParam(aMsg, aIter, &aResult->mCodeValue) &&
         ReadParam(aMsg, aIter, &aResult->mKeyCode) &&
         ReadParam(aMsg, aIter, &aResult->mCharCode) &&
@@ -451,18 +453,17 @@ struct ParamTraits<mozilla::WidgetKeyboa
 #endif
         )
     {
       aResult->mKeyNameIndex = static_cast<mozilla::KeyNameIndex>(keyNameIndex);
       aResult->mCodeNameIndex =
         static_cast<mozilla::CodeNameIndex>(codeNameIndex);
       aResult->mNativeKeyEvent = nullptr;
       aResult->mInputMethodAppState =
-        static_cast<mozilla::WidgetKeyboardEvent::InputMethodAppState>
-          (inputMethodAppState);
+        static_cast<paramType::InputMethodAppState>(inputMethodAppState);
       return true;
     }
     return false;
   }
 };
 
 template<>
 struct ParamTraits<mozilla::InternalBeforeAfterKeyboardEvent>