Bug 1176462 - Remove nsTableDecoderSupport. r=smontagu
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Mon, 22 Jun 2015 23:01:40 +0900
changeset 280788 22ad2f837fdaf7a04baef68ed8a7d7ca6e5d24ef
parent 280787 5b3a945118134a4f12c03619d76ee05bcbafc23b
child 280789 43ac34bcae77506daacdbea720283815682ab7da
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmontagu
bugs1176462
milestone41.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 1176462 - Remove nsTableDecoderSupport. r=smontagu
intl/uconv/nsUCSupport.h
intl/uconv/ucvcn/nsGBKToUnicode.cpp
intl/uconv/ucvcn/nsGBKToUnicode.h
intl/uconv/util/nsUCSupport.cpp
--- a/intl/uconv/nsUCSupport.h
+++ b/intl/uconv/nsUCSupport.h
@@ -145,53 +145,16 @@ public:
       char16_t * aDest, int32_t * aDestLength);
   NS_IMETHOD Reset();
   NS_IMETHOD GetMaxLength(const char *aSrc,
                           int32_t aSrcLength,
                           int32_t* aDestLength);
 };
 
 //----------------------------------------------------------------------
-// Class nsTableDecoderSupport [declaration]
-
-/**
- * Support class for a single-table-driven Unicode decoder.
- * 
- * @created         15/Mar/1999
- * @author  Catalin Rotaru [CATA]
- */
-class nsTableDecoderSupport : public nsBufferDecoderSupport
-{
-public:
-
-  /**
-   * Class constructor.
-   */
-  nsTableDecoderSupport(uScanClassID aScanClass, uShiftInTable * aShiftInTable,
-      uMappingTable * aMappingTable, uint32_t aMaxLengthFactor);
-
-  /**
-   * Class destructor.
-   */
-  virtual ~nsTableDecoderSupport();
-
-protected:
-
-  uScanClassID              mScanClass;
-  uShiftInTable             * mShiftInTable;
-  uMappingTable             * mMappingTable;
-
-  //--------------------------------------------------------------------
-  // Subclassing of nsBufferDecoderSupport class [declaration]
-
-  NS_IMETHOD ConvertNoBuff(const char * aSrc, int32_t * aSrcLength, 
-      char16_t * aDest, int32_t * aDestLength);
-};
-
-//----------------------------------------------------------------------
 // Class nsMultiTableDecoderSupport [declaration]
 
 /**
  * Support class for a multi-table-driven Unicode decoder.
  * 
  * @created         24/Mar/1999
  * @author  Catalin Rotaru [CATA]
  */
--- a/intl/uconv/ucvcn/nsGBKToUnicode.cpp
+++ b/intl/uconv/ucvcn/nsGBKToUnicode.cpp
@@ -7,65 +7,31 @@
  * 
  *
  * @created         07/Sept/1999
  * @author  Yueheng Xu, Yueheng.Xu@intel.com
  */
 
 #include "nsGBKToUnicode.h"
 #include "gbku.h"
-
-//------------------------------------------------------------
-// nsGB18030Unique2BytesToUnicode
-//------------------------------------------------------------
-class nsGB18030Unique2BytesToUnicode : public nsTableDecoderSupport 
-{
-public:
-  nsGB18030Unique2BytesToUnicode();
-  virtual ~nsGB18030Unique2BytesToUnicode() 
-    { }
-protected:
-};
+#include "nsUnicodeDecodeHelper.h"
 
 static const uint16_t g_utGB18030Unique2Bytes[] = {
 #include "gb18030uniq2b.ut"
 };
-nsGB18030Unique2BytesToUnicode::nsGB18030Unique2BytesToUnicode() 
-  : nsTableDecoderSupport(u2BytesCharset, nullptr,
-        (uMappingTable*) &g_utGB18030Unique2Bytes, 1) 
-{
-}
-
-//------------------------------------------------------------
-// nsGB18030Unique4BytesToUnicode
-//------------------------------------------------------------
-class nsGB18030Unique4BytesToUnicode : public nsTableDecoderSupport 
-{
-public:
-  nsGB18030Unique4BytesToUnicode();
-  virtual ~nsGB18030Unique4BytesToUnicode() 
-    { }
-protected:
-};
 
 static const uint16_t g_utGB18030Unique4Bytes[] = {
 #include "gb180304bytes.ut"
 };
-nsGB18030Unique4BytesToUnicode::nsGB18030Unique4BytesToUnicode() 
-  : nsTableDecoderSupport(u4BytesGB18030Charset, nullptr,
-        (uMappingTable*) &g_utGB18030Unique4Bytes, 1) 
-{
-}
-
 
 //----------------------------------------------------------------------
-// Class nsGBKToUnicode [implementation]
+// Class nsGB18030ToUnicode [implementation]
 
 //----------------------------------------------------------------------
-// Subclassing of nsTablesDecoderSupport class [implementation]
+// Subclassing of nsBufferDecoderSupport class [implementation]
 
 #define LEGAL_GBK_MULTIBYTE_FIRST_BYTE(c)  \
       (UINT8_IN_RANGE(0x81, (c), 0xFE))
 #define FIRST_BYTE_IS_SURROGATE(c)  \
       (UINT8_IN_RANGE(0x90, (c), 0xFE))
 #define LEGAL_GBK_2BYTE_SECOND_BYTE(c) \
       (UINT8_IN_RANGE(0x40, (c), 0x7E)|| UINT8_IN_RANGE(0x80, (c), 0xFE))
 #define LEGAL_GBK_4BYTE_SECOND_BYTE(c) \
@@ -202,24 +168,16 @@ NS_IMETHODIMP nsGB18030ToUnicode::Conver
     iDestlen++;
     aDest++;
     *aSrcLength = i+1;
   }
   *aDestLength = iDestlen;
   return rv;
 }
 
-void nsGB18030ToUnicode::CreateExtensionDecoder()
-{
-  mExtensionDecoder = new nsGB18030Unique2BytesToUnicode();
-}
-void nsGB18030ToUnicode::Create4BytesDecoder()
-{
-  m4BytesDecoder = new nsGB18030Unique4BytesToUnicode();
-}
 bool nsGB18030ToUnicode::DecodeToSurrogate(const char* aSrc, char16_t* aOut)
 {
   NS_ASSERTION(FIRST_BYTE_IS_SURROGATE(aSrc[0]),       "illegal first byte");
   NS_ASSERTION(LEGAL_GBK_4BYTE_SECOND_BYTE(aSrc[1]),   "illegal second byte");
   NS_ASSERTION(LEGAL_GBK_4BYTE_THIRD_BYTE(aSrc[2]),    "illegal third byte");
   NS_ASSERTION(LEGAL_GBK_4BYTE_FORTH_BYTE(aSrc[3]),    "illegal forth byte");
   if(! FIRST_BYTE_IS_SURROGATE(aSrc[0]))
     return false;
@@ -245,48 +203,37 @@ bool nsGB18030ToUnicode::DecodeToSurroga
 
   *aOut++ = 0xD800 | (idx >> 10);
   *aOut = 0xDC00 | (0x000003FF & idx);
 
   return true;
 }
 bool nsGB18030ToUnicode::TryExtensionDecoder(const char* aSrc, char16_t* aOut)
 {
-  if(!mExtensionDecoder)
-    CreateExtensionDecoder();
-  NS_ASSERTION(mExtensionDecoder, "cannot creqte 2 bytes unique converter");
-  if(mExtensionDecoder)
-  {
-    nsresult res = mExtensionDecoder->Reset();
-    NS_ASSERTION(NS_SUCCEEDED(res), "2 bytes unique conversoin reset failed");
-    int32_t len = 2;
-    int32_t dstlen = 1;
-    res = mExtensionDecoder->Convert(aSrc,&len, aOut, &dstlen); 
-    NS_ASSERTION(NS_FAILED(res) || ((len==2) && (dstlen == 1)), 
-       "some strange conversion result");
-     // if we failed, we then just use the 0xfffd 
-     // therefore, we ignore the res here. 
-    if(NS_SUCCEEDED(res)) 
-      return true;
-  }
-  return  false;
+  int32_t len = 2;
+  int32_t dstlen = 1;
+  nsresult res =
+    nsUnicodeDecodeHelper::ConvertByTable(aSrc, &len, aOut, &dstlen,
+                                          u2BytesCharset, nullptr,
+                                          (uMappingTable*) &g_utGB18030Unique2Bytes,
+                                          false);
+  NS_ASSERTION(NS_FAILED(res) || ((len==2) && (dstlen == 1)),
+               "some strange conversion result");
+  // if we failed, we then just use the 0xfffd
+  // therefore, we ignore the res here.
+  return NS_SUCCEEDED(res);
 }
 
 bool nsGB18030ToUnicode::Try4BytesDecoder(const char* aSrc, char16_t* aOut)
 {
-  if(!m4BytesDecoder)
-    Create4BytesDecoder();
-  if(m4BytesDecoder)
-  {
-    nsresult res = m4BytesDecoder->Reset();
-    NS_ASSERTION(NS_SUCCEEDED(res), "4 bytes unique conversoin reset failed");
-    int32_t len = 4;
-    int32_t dstlen = 1;
-    res = m4BytesDecoder->Convert(aSrc,&len, aOut, &dstlen); 
-    NS_ASSERTION(NS_FAILED(res) || ((len==4) && (dstlen == 1)), 
-       "some strange conversion result");
-     // if we failed, we then just use the 0xfffd 
-     // therefore, we ignore the res here. 
-    if(NS_SUCCEEDED(res)) 
-      return true;
-  }
-  return  false;
+  int32_t len = 4;
+  int32_t dstlen = 1;
+  nsresult res =
+    nsUnicodeDecodeHelper::ConvertByTable(aSrc, &len, aOut, &dstlen,
+                                          u4BytesGB18030Charset, nullptr,
+                                          (uMappingTable*) &g_utGB18030Unique4Bytes,
+                                          false); 
+  NS_ASSERTION(NS_FAILED(res) || ((len==4) && (dstlen == 1)),
+               "some strange conversion result");
+  // if we failed, we then just use the 0xfffd
+  // therefore, we ignore the res here.
+  return NS_SUCCEEDED(res);
 }
--- a/intl/uconv/ucvcn/nsGBKToUnicode.h
+++ b/intl/uconv/ucvcn/nsGBKToUnicode.h
@@ -24,33 +24,27 @@ class nsGB18030ToUnicode : public nsBuff
 {
 public:
 		  
   /**
    * Class constructor.
    */
   nsGB18030ToUnicode() : nsBufferDecoderSupport(1)
   {
-    mExtensionDecoder = nullptr;
-    m4BytesDecoder = nullptr;
   }
 
 protected:
 
   //--------------------------------------------------------------------
-  // Subclassing of nsDecoderSupport class [declaration]
+  // Subclassing of nsBufferDecoderSupport class [declaration]
   NS_IMETHOD ConvertNoBuff(const char* aSrc, int32_t * aSrcLength, char16_t *aDest, int32_t * aDestLength);
 
 protected:
   nsGBKConvUtil mUtil;
-  nsCOMPtr<nsIUnicodeDecoder> mExtensionDecoder;
-  nsCOMPtr<nsIUnicodeDecoder> m4BytesDecoder;
 
-  void CreateExtensionDecoder();
-  void Create4BytesDecoder();
   bool TryExtensionDecoder(const char* aSrc, char16_t* aDest);
   bool Try4BytesDecoder(const char* aSrc, char16_t* aDest);
   bool DecodeToSurrogate(const char* aSrc, char16_t* aDest);
 
 };
 
 #endif /* nsGBKToUnicode_h___ */
 
--- a/intl/uconv/util/nsUCSupport.cpp
+++ b/intl/uconv/util/nsUCSupport.cpp
@@ -194,49 +194,16 @@ NS_IMETHODIMP nsBufferDecoderSupport::Ge
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   *aDestLength = length.value();
   return NS_OK;
 }
 
 //----------------------------------------------------------------------
-// Class nsTableDecoderSupport [implementation]
-
-nsTableDecoderSupport::nsTableDecoderSupport(uScanClassID aScanClass,
-                                             uShiftInTable* aShiftInTable,
-                                             uMappingTable* aMappingTable,
-                                             uint32_t aMaxLengthFactor)
-: nsBufferDecoderSupport(aMaxLengthFactor)
-{
-  mScanClass = aScanClass;
-  mShiftInTable = aShiftInTable;
-  mMappingTable = aMappingTable;
-}
-
-nsTableDecoderSupport::~nsTableDecoderSupport()
-{
-}
-
-//----------------------------------------------------------------------
-// Subclassing of nsBufferDecoderSupport class [implementation]
-
-NS_IMETHODIMP nsTableDecoderSupport::ConvertNoBuff(const char* aSrc,
-                                                   int32_t* aSrcLength,
-                                                   char16_t* aDest,
-                                                   int32_t* aDestLength)
-{
-  return nsUnicodeDecodeHelper::ConvertByTable(aSrc, aSrcLength,
-                                               aDest, aDestLength,
-                                               mScanClass,
-                                               mShiftInTable, mMappingTable,
-                                               mErrBehavior == kOnError_Signal);
-}
-
-//----------------------------------------------------------------------
 // Class nsMultiTableDecoderSupport [implementation]
 
 nsMultiTableDecoderSupport::nsMultiTableDecoderSupport(
                             int32_t aTableCount,
                             const uRange* aRangeArray,
                             uScanClassID* aScanClassArray,
                             uMappingTable** aMappingTable,
                             uint32_t aMaxLengthFactor)