From 5abb921f9866fb2b8949a3ff102d3d6a48f5d548 Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Fri, 29 Jun 2001 23:08:23 +0000 Subject: [PATCH] Make ns[C]StringKey cooperate better with new string classes (although it doesn't participate in sharing). When created (non-cloned) from a flat string it will be dependent (as it was when created from ns[C]String), but it will copy non-flat strings. --- xpcom/ds/nsHashtable.cpp | 37 +++++++++++++++++++++++++++++++++---- xpcom/ds/nsHashtable.h | 6 ++++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/xpcom/ds/nsHashtable.cpp b/xpcom/ds/nsHashtable.cpp index d6f2133018cf..946d340dd8ef 100644 --- a/xpcom/ds/nsHashtable.cpp +++ b/xpcom/ds/nsHashtable.cpp @@ -33,6 +33,7 @@ #include "prmem.h" #include "prlog.h" #include "nsHashtable.h" +#include "nsReadableUtils.h" //////////////////////////////////////////////////////////////////////////////// // These functions really should be part of nspr, and have internal knowledge @@ -390,8 +391,22 @@ void nsHashtable::Reset(nsHashtableEnumFunc destroyFunc, void* closure) //////////////////////////////////////////////////////////////////////////////// -nsCStringKey::nsCStringKey(const nsCString& str) - : mStr((char*)str.get()), mStrLen(str.Length()), mOwnership(OWN_CLONE) +nsCStringKey::nsCStringKey(const nsAFlatCString& str) + : mStr(NS_CONST_CAST(char*, str.get())), + mStrLen(str.Length()), + mOwnership(OWN_CLONE) +{ + NS_ASSERTION(mStr, "null string key"); +#ifdef DEBUG + mKeyType = CStringKey; +#endif + MOZ_COUNT_CTOR(nsCStringKey); +} + +nsCStringKey::nsCStringKey(const nsACString& str) + : mStr(ToNewCString(str)), + mStrLen(str.Length()), + mOwnership(OWN) { NS_ASSERTION(mStr, "null string key"); #ifdef DEBUG @@ -456,8 +471,22 @@ nsCStringKey::Clone() const //////////////////////////////////////////////////////////////////////////////// -nsStringKey::nsStringKey(const nsAReadableString& str) - : mStr(NS_CONST_CAST(PRUnichar*, NS_STATIC_CAST(const PRUnichar *, PromiseFlatString(str).get()))), mStrLen(str.Length()), mOwnership(OWN_CLONE) +nsStringKey::nsStringKey(const nsAFlatString& str) + : mStr(NS_CONST_CAST(PRUnichar*, str.get())), + mStrLen(str.Length()), + mOwnership(OWN_CLONE) +{ + NS_ASSERTION(mStr, "null string key"); +#ifdef DEBUG + mKeyType = StringKey; +#endif + MOZ_COUNT_CTOR(nsStringKey); +} + +nsStringKey::nsStringKey(const nsAString& str) + : mStr(ToNewUnicode(str)), + mStrLen(str.Length()), + mOwnership(OWN) { NS_ASSERTION(mStr, "null string key"); #ifdef DEBUG diff --git a/xpcom/ds/nsHashtable.h b/xpcom/ds/nsHashtable.h index 042a7e7cb9e1..aa2b44ee706b 100644 --- a/xpcom/ds/nsHashtable.h +++ b/xpcom/ds/nsHashtable.h @@ -277,7 +277,8 @@ public: }; nsCStringKey(const char* str, PRInt32 strLen = -1, Ownership own = OWN_CLONE); - nsCStringKey(const nsCString& str); + nsCStringKey(const nsAFlatCString& str); + nsCStringKey(const nsACString& str); ~nsCStringKey(void); PRUint32 HashCode(void) const; @@ -306,7 +307,8 @@ public: }; nsStringKey(const PRUnichar* str, PRInt32 strLen = -1, Ownership own = OWN_CLONE); - nsStringKey(const nsAReadableString& str); + nsStringKey(const nsAFlatString& str); + nsStringKey(const nsAString& str); ~nsStringKey(void); PRUint32 HashCode(void) const;