From de3dca4e6076fb215fe0412c600ae6bf41511f21 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Sat, 21 Jul 2007 03:00:03 +0000 Subject: [PATCH] Don't generate state keys at all, if there's nothing to get. Bug 388387, r+sr=sicking. git-svn-id: svn://10.0.0.236/trunk@230408 18797224-902f-48f8-a5cc-f745e15eee43 --- .../content/html/content/src/nsGenericHTMLElement.cpp | 11 +++++++++-- .../content/html/content/src/nsGenericHTMLElement.h | 3 +++ mozilla/layout/base/nsILayoutHistoryState.h | 9 +++++++-- mozilla/layout/base/nsLayoutHistoryState.cpp | 7 +++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index 6b56cd33e45..44a96025745 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -1733,7 +1733,7 @@ nsGenericHTMLElement::GetPrimaryPresState(nsGenericHTMLElement* aContent, nsCOMPtr history; nsCAutoString key; - GetLayoutHistoryAndKey(aContent, getter_AddRefs(history), key); + GetLayoutHistoryAndKey(aContent, PR_FALSE, getter_AddRefs(history), key); if (history) { // Get the pres state for this key, if it doesn't exist, create one @@ -1752,6 +1752,7 @@ nsGenericHTMLElement::GetPrimaryPresState(nsGenericHTMLElement* aContent, nsresult nsGenericHTMLElement::GetLayoutHistoryAndKey(nsGenericHTMLElement* aContent, + PRBool aRead, nsILayoutHistoryState** aHistory, nsACString& aKey) { @@ -1771,6 +1772,11 @@ nsGenericHTMLElement::GetLayoutHistoryAndKey(nsGenericHTMLElement* aContent, return NS_OK; } + if (aRead && !(*aHistory)->HasStates()) { + NS_RELEASE(*aHistory); + return NS_OK; + } + // // Get the state key // @@ -1801,7 +1807,8 @@ nsGenericHTMLElement::RestoreFormControlState(nsGenericHTMLElement* aContent, { nsCOMPtr history; nsCAutoString key; - nsresult rv = GetLayoutHistoryAndKey(aContent, getter_AddRefs(history), key); + nsresult rv = GetLayoutHistoryAndKey(aContent, PR_TRUE, + getter_AddRefs(history), key); if (!history) { return PR_FALSE; } diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.h b/mozilla/content/html/content/src/nsGenericHTMLElement.h index b497be39526..644bff7df19 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.h +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.h @@ -527,10 +527,13 @@ public: * piece of content. * * @param aContent the content to generate the key for + * @param aRead if true, won't return a layout history state (and won't + * generate a key) if the layout history state is empty. * @param aState the history state object (out param) * @param aKey the key (out param) */ static nsresult GetLayoutHistoryAndKey(nsGenericHTMLElement* aContent, + PRBool aRead, nsILayoutHistoryState** aState, nsACString& aKey); /** diff --git a/mozilla/layout/base/nsILayoutHistoryState.h b/mozilla/layout/base/nsILayoutHistoryState.h index 1df07a1da45..52a15dc450a 100644 --- a/mozilla/layout/base/nsILayoutHistoryState.h +++ b/mozilla/layout/base/nsILayoutHistoryState.h @@ -50,8 +50,8 @@ class nsPresState; #define NS_ILAYOUTHISTORYSTATE_IID \ -{0xe6abfb7c, 0x6624, 0x4b4d, \ -{0x9d, 0xfe, 0xea, 0x62, 0xae, 0xfe, 0x03, 0x31}} +{ 0x99003f0f, 0x7ade, 0x44a1, \ + { 0x81, 0x74, 0xe3, 0x6a, 0xa5, 0xbb, 0x6b, 0x10 } } class nsILayoutHistoryState : public nsISupports { public: @@ -74,6 +74,11 @@ class nsILayoutHistoryState : public nsISupports { * Remove the state object for |aKey|. */ NS_IMETHOD RemoveState(const nsCString& aKey) = 0; + + /** + * Check whether this history has any states in it + */ + NS_IMETHOD_(PRBool) HasStates() const = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsILayoutHistoryState, diff --git a/mozilla/layout/base/nsLayoutHistoryState.cpp b/mozilla/layout/base/nsLayoutHistoryState.cpp index 61ec23edd12..61403f1a922 100644 --- a/mozilla/layout/base/nsLayoutHistoryState.cpp +++ b/mozilla/layout/base/nsLayoutHistoryState.cpp @@ -58,6 +58,7 @@ public: NS_IMETHOD AddState(const nsCString& aKey, nsPresState* aState); NS_IMETHOD GetState(const nsCString& aKey, nsPresState** aState); NS_IMETHOD RemoveState(const nsCString& aKey); + NS_IMETHOD_(PRBool) HasStates() const; private: @@ -116,3 +117,9 @@ nsLayoutHistoryState::RemoveState(const nsCString& aKey) mStates.Remove(aKey); return NS_OK; } + +NS_IMETHODIMP_(PRBool) +nsLayoutHistoryState::HasStates() const +{ + return mStates.Count() != 0; +}