Bug 1262324 (part 2) - Introduce nsUConvProp. r=emk.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 06 Apr 2016 13:31:38 +1000
changeset 331773 835b1d9e49182f5a91e9dc931c19b836e14085ba
parent 331772 978884d01e8ef968262e54138bf43acdbbc603b6
child 331774 1505798c15933f80fc3b4303ea96337c54943693
push id1146
push userCallek@gmail.com
push dateMon, 25 Jul 2016 16:35:44 +0000
treeherdermozilla-release@a55778f9cd5a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1262324
milestone48.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 1262324 (part 2) - Introduce nsUConvProp. r=emk. This patch fixes the hack of using a trio of |const char*| pointers to represent a property that has two strings and a length.
dom/encoding/EncodingUtils.cpp
dom/encoding/FallbackEncoding.cpp
intl/locale/nsLanguageAtomService.cpp
intl/locale/nsLanguageAtomService.h
intl/locale/nsUConvPropertySearch.cpp
intl/locale/nsUConvPropertySearch.h
intl/locale/props2arrays.py
intl/locale/unix/nsUNIXCharset.cpp
intl/locale/windows/nsWinCharset.cpp
--- a/dom/encoding/EncodingUtils.cpp
+++ b/dom/encoding/EncodingUtils.cpp
@@ -10,21 +10,21 @@
 #include "nsUConvPropertySearch.h"
 #include "nsIUnicodeDecoder.h"
 #include "nsIUnicodeEncoder.h"
 #include "nsComponentManagerUtils.h"
 
 namespace mozilla {
 namespace dom {
 
-static const char* const labelsEncodings[][3] = {
+static const nsUConvProp labelsEncodings[] = {
 #include "labelsencodings.properties.h"
 };
 
-static const char* const encodingsGroups[][3] = {
+static const nsUConvProp encodingsGroups[] = {
 #include "encodingsgroups.properties.h"
 };
 
 bool
 EncodingUtils::FindEncodingForLabel(const nsACString& aLabel,
                                     nsACString& aOutEncoding)
 {
   // Save aLabel first because it may refer the same string as aOutEncoding.
--- a/dom/encoding/FallbackEncoding.cpp
+++ b/dom/encoding/FallbackEncoding.cpp
@@ -10,25 +10,25 @@
 #include "nsUConvPropertySearch.h"
 #include "nsIChromeRegistry.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 
 namespace mozilla {
 namespace dom {
 
-static const char* const localesFallbacks[][3] = {
+static const nsUConvProp localesFallbacks[] = {
 #include "localesfallbacks.properties.h"
 };
 
-static const char* const domainsFallbacks[][3] = {
+static const nsUConvProp domainsFallbacks[] = {
 #include "domainsfallbacks.properties.h"
 };
 
-static const char* const nonParticipatingDomains[][3] = {
+static const nsUConvProp nonParticipatingDomains[] = {
 #include "nonparticipatingdomains.properties.h"
 };
 
 FallbackEncoding* FallbackEncoding::sInstance = nullptr;
 bool FallbackEncoding::sGuessFallbackFromTopLevelDomain = true;
 
 FallbackEncoding::FallbackEncoding()
 {
--- a/intl/locale/nsLanguageAtomService.cpp
+++ b/intl/locale/nsLanguageAtomService.cpp
@@ -10,17 +10,17 @@
 #include "nsIAtom.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Services.h"
 #include "nsServiceManagerUtils.h"
 #include "mozilla/dom/EncodingUtils.h"
 
 using namespace mozilla;
 
-static const char* const kLangGroups[][3] = {
+static const nsUConvProp kLangGroups[] = {
 #include "langGroups.properties.h"
 };
 
 NS_IMPL_ISUPPORTS(nsLanguageAtomService, nsILanguageAtomService)
 
 nsLanguageAtomService::nsLanguageAtomService()
 {
 }
--- a/intl/locale/nsLanguageAtomService.h
+++ b/intl/locale/nsLanguageAtomService.h
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsCOMPtr.h"
 #include "nsILanguageAtomService.h"
 #include "nsIStringBundle.h"
 #include "nsInterfaceHashtable.h"
 #include "nsIAtom.h"
+#include "nsUConvPropertySearch.h"
 #include "mozilla/Attributes.h"
 
 #define NS_LANGUAGEATOMSERVICE_CID \
   {0xB7C65853, 0x2996, 0x435E, {0x96, 0x54, 0xDC, 0xC1, 0x78, 0xAA, 0xB4, 0x8C}}
 
 class nsLanguageAtomService final : public nsILanguageAtomService
 {
 public:
--- a/intl/locale/nsUConvPropertySearch.cpp
+++ b/intl/locale/nsUConvPropertySearch.cpp
@@ -8,37 +8,37 @@
 #include "mozilla/BinarySearch.h"
 
 namespace {
 
 struct PropertyComparator
 {
   const nsCString& mKey;
   explicit PropertyComparator(const nsCString& aKey) : mKey(aKey) {}
-  int operator()(const char* const (&aProperty)[3]) const {
-    return mKey.Compare(aProperty[0]);
+  int operator()(const nsUConvProp& aProperty) const {
+    return mKey.Compare(aProperty.mKey);
   }
 };
 
 } // namespace
 
 // static
 nsresult
-nsUConvPropertySearch::SearchPropertyValue(const char* const aProperties[][3],
+nsUConvPropertySearch::SearchPropertyValue(const nsUConvProp aProperties[],
                                            int32_t aNumberOfProperties,
                                            const nsACString& aKey,
                                            nsACString& aValue)
 {
   using mozilla::BinarySearchIf;
 
   const nsCString& flat = PromiseFlatCString(aKey);
   size_t index;
   if (BinarySearchIf(aProperties, 0, aNumberOfProperties,
                      PropertyComparator(flat), &index)) {
-    nsDependentCString val(aProperties[index][1],
-                           NS_PTR_TO_UINT32(aProperties[index][2]));
+    nsDependentCString val(aProperties[index].mValue,
+                           aProperties[index].mValueLength);
     aValue.Assign(val);
     return NS_OK;
   }
 
   aValue.Truncate();
   return NS_ERROR_FAILURE;
 }
--- a/intl/locale/nsUConvPropertySearch.h
+++ b/intl/locale/nsUConvPropertySearch.h
@@ -2,29 +2,36 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsUConvPropertySearch_h_
 #define nsUConvPropertySearch_h_
 
 #include "nsStringFwd.h"
 
+struct nsUConvProp
+{
+    const char* const mKey;
+    const char* const mValue;
+    const uint32_t mValueLength;
+};
+
 class nsUConvPropertySearch
 {
   public:
     /**
      * Looks up a property by value.
      *
      * @param aProperties
      *   the static property array
      * @param aKey
      *   the key to look up
      * @param aValue
      *   the return value (empty string if not found)
      * @return NS_OK if found or NS_ERROR_FAILURE if not found
      */
-    static nsresult SearchPropertyValue(const char* const aProperties[][3],
+    static nsresult SearchPropertyValue(const nsUConvProp aProperties[],
                                         int32_t aNumberOfProperties,
                                         const nsACString& aKey,
                                         nsACString& aValue);
 };
 
 #endif /* nsUConvPropertySearch_h_ */
--- a/intl/locale/props2arrays.py
+++ b/intl/locale/props2arrays.py
@@ -16,12 +16,12 @@ def main(header, propFile):
           mappings[parts[0].strip()] = parts[1].strip()
  
   keys = mappings.keys()
   keys.sort()
 
   header.write("// This is a generated file. Please do not edit.\n")
   header.write("// Please edit the corresponding .properties file instead.\n")
 
-  entries = ['{ "%s", "%s", (const char*)NS_INT32_TO_PTR(%d) }'
+  entries = ['{ "%s", "%s", %d }'
              % (key, mappings[key], len(mappings[key])) for key in keys]
   header.write(',\n'.join(entries) + '\n')
 
--- a/intl/locale/unix/nsUNIXCharset.cpp
+++ b/intl/locale/unix/nsUNIXCharset.cpp
@@ -24,17 +24,17 @@
 #include "nsPlatformCharset.h"
 #include "prinit.h"
 #include "nsUnicharUtils.h"
 #include "mozilla/dom/EncodingUtils.h"
 
 using mozilla::dom::EncodingUtils;
 using namespace mozilla;
 
-static const char* const kUnixCharsets[][3] = {
+static const nsUConvProp kUnixCharsets[] = {
 #include "unixcharset.properties.h"
 };
 
 NS_IMPL_ISUPPORTS(nsPlatformCharset, nsIPlatformCharset)
 
 nsPlatformCharset::nsPlatformCharset()
 {
 }
--- a/intl/locale/windows/nsWinCharset.cpp
+++ b/intl/locale/windows/nsWinCharset.cpp
@@ -12,17 +12,17 @@
 #include "nsCOMPtr.h"
 #include "nsReadableUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsPlatformCharset.h"
 #include "nsEncoderDecoderUtils.h"
 
 using namespace mozilla;
 
-static const char* const kWinCharsets[][3] = {
+static const nsUConvProp kWinCharsets[] = {
 #include "wincharset.properties.h"
 };
 
 NS_IMPL_ISUPPORTS(nsPlatformCharset, nsIPlatformCharset)
 
 nsPlatformCharset::nsPlatformCharset()
 {
   nsAutoString acpKey(NS_LITERAL_STRING("acp."));