Bug 1428863 - Add TokenStreamChars::asSpecific to consolidate a downcast into a helper function. r=arai
authorJeff Walden <jwalden@mit.edu>
Wed, 27 Dec 2017 10:21:23 -0500
changeset 399890 118c5618f34898c1dc4fd562401acc6298529c47
parent 399889 c1406363fb17e2409dbbbf9291c3f7dd4cdf50e5
child 399891 325b6c9e845e8857d5666beb574970253fd8d574
push id33279
push useraciure@mozilla.com
push dateThu, 18 Jan 2018 21:53:37 +0000
treeherdermozilla-central@cffb3cd9dbb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1428863
milestone59.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 1428863 - Add TokenStreamChars::asSpecific to consolidate a downcast into a helper function. r=arai
js/src/frontend/TokenStream.cpp
js/src/frontend/TokenStream.h
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -1257,20 +1257,17 @@ IsTokenSane(Token* tp)
 }
 #endif
 
 template<class AnyCharsAccess>
 bool
 TokenStreamChars<char16_t, AnyCharsAccess>::matchTrailForLeadSurrogate(char16_t lead,
                                                                        uint32_t* codePoint)
 {
-    static_assert(mozilla::IsBaseOf<TokenStreamChars<char16_t, AnyCharsAccess>,
-                                    TokenStreamSpecific<char16_t, AnyCharsAccess>>::value,
-                  "static_cast below presumes an inheritance relationship");
-    auto* ts = static_cast<TokenStreamSpecific<char16_t, AnyCharsAccess>*>(this);
+    TokenStreamSpecific* ts = asSpecific();
 
     int32_t maybeTrail = ts->getCharIgnoreEOL();
     if (!unicode::IsTrailSurrogate(maybeTrail)) {
         ts->ungetCharIgnoreEOL(maybeTrail);
         return false;
     }
 
     *codePoint = unicode::UTF16Decode(lead, maybeTrail);
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -128,16 +128,17 @@
  * TokenStreamSpecific declarer to specify this is more explicit), we couldn't.
  */
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/PodOperations.h"
+#include "mozilla/TypeTraits.h"
 #include "mozilla/Unused.h"
 
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdio.h>
 
 #include "jscntxt.h"
 #include "jspubtd.h"
@@ -946,18 +947,28 @@ class TokenStreamCharsBase
 };
 
 template<typename CharT, class AnyCharsAccess> class TokenStreamChars;
 
 template<class AnyCharsAccess>
 class TokenStreamChars<char16_t, AnyCharsAccess>
   : public TokenStreamCharsBase<char16_t>
 {
+    using Self = TokenStreamChars<char16_t, AnyCharsAccess>;
     using CharsBase = TokenStreamCharsBase<char16_t>;
 
+    using TokenStreamSpecific = frontend::TokenStreamSpecific<char16_t, AnyCharsAccess>;
+
+    TokenStreamSpecific* asSpecific() {
+        static_assert(mozilla::IsBaseOf<Self, TokenStreamSpecific>::value,
+                      "static_cast below presumes an inheritance relationship");
+
+        return static_cast<TokenStreamSpecific*>(this);
+    }
+
     bool matchTrailForLeadSurrogate(char16_t lead, uint32_t* codePoint);
 
   public:
     using CharsBase::CharsBase;
 
     TokenStreamAnyChars& anyChars() {
         return AnyCharsAccess::anyChars(this);
     }