Bug 1547478 - Make the |CodeUncompressedData| generic lambda inside |ScriptSource::xdrData| instead be a static member function in |ScriptSource|, avoiding the need to pass an ignored |Unit| argument to it purely for overload selection. r=tcampbell
authorJeff Walden <jwalden@mit.edu>
Mon, 29 Apr 2019 12:36:35 -0700
changeset 530703 0494a9f3230c58de2120b5a02dca77f11144298d
parent 530702 ce9c122d9c32087f63c8d5a053cb24c97a546bbe
child 530704 5fe6df92def0d5de136974cc5c3a9183eb9b7041
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1547478
milestone68.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 1547478 - Make the |CodeUncompressedData| generic lambda inside |ScriptSource::xdrData| instead be a static member function in |ScriptSource|, avoiding the need to pass an ignored |Unit| argument to it purely for overload selection. r=tcampbell Differential Revision: https://phabricator.services.mozilla.com/D29263
js/src/vm/JSScript.cpp
js/src/vm/JSScript.h
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -2637,16 +2637,49 @@ XDRResult ScriptSource::xdrUncompressedS
   }
 
   SourceEncoder<char16_t> encoder(xdr, this, uncompressedLength);
   return encoder.encode();
 }
 
 }  // namespace js
 
+template <typename Unit, XDRMode mode>
+/* static */
+XDRResult ScriptSource::codeUncompressedData(XDRState<mode>* const xdr,
+                                             ScriptSource* const ss,
+                                             bool retrievable) {
+  static_assert(std::is_same<Unit, Utf8Unit>::value ||
+                    std::is_same<Unit, char16_t>::value,
+                "should handle UTF-8 and UTF-16");
+
+  if (mode == XDR_ENCODE) {
+    MOZ_ASSERT(ss->data.is<Uncompressed<Unit>>());
+  }
+
+  MOZ_ASSERT(retrievable == ss->sourceRetrievable());
+
+  if (retrievable) {
+    // It's unnecessary to code uncompressed data if it can just be retrieved
+    // using the source hook.
+    if (mode == XDR_DECODE) {
+      ss->data = SourceType(Retrievable<Unit>());
+    }
+    return Ok();
+  }
+
+  uint32_t uncompressedLength;
+  if (mode == XDR_ENCODE) {
+    uncompressedLength = ss->data.as<Uncompressed<Unit>>().length();
+  }
+  MOZ_TRY(xdr->codeUint32(&uncompressedLength));
+
+  return ss->xdrUncompressedSource(xdr, sizeof(Unit), uncompressedLength);
+}
+
 template <XDRMode mode>
 /* static */
 XDRResult ScriptSource::xdrData(XDRState<mode>* const xdr,
                                 ScriptSource* const ss) {
   // Retrievability is kept outside |ScriptSource::data| (and not solely as
   // distinct variant types within it) because retrievable compressed or
   // uncompressed data need not be XDR'd.
   uint8_t retrievable;
@@ -2766,45 +2799,16 @@ XDRResult ScriptSource::xdrData(XDRState
       void* bytes =
           const_cast<char*>(ss->data.as<Compressed<Unit>>().raw.chars());
       MOZ_TRY(xdr->codeBytes(bytes, compressedLength));
     }
 
     return Ok();
   };
 
-  auto CodeUncompressedData = [xdr, ss, &retrievable](auto unit) -> XDRResult {
-    using Unit = decltype(unit);
-
-    static_assert(std::is_same<Unit, Utf8Unit>::value ||
-                      std::is_same<Unit, char16_t>::value,
-                  "should handle UTF-8 and UTF-16");
-
-    if (mode == XDR_ENCODE) {
-      MOZ_ASSERT(ss->data.is<Uncompressed<Unit>>());
-    }
-
-    if (retrievable) {
-      // It's unnecessary to code uncompressed data if it can just be retrieved
-      // using the source hook.
-      if (mode == XDR_DECODE) {
-        ss->data = SourceType(Retrievable<Unit>());
-      }
-      return Ok();
-    }
-
-    uint32_t uncompressedLength = 0;
-    if (mode == XDR_ENCODE) {
-      uncompressedLength = ss->data.as<Uncompressed<Unit>>().length();
-    }
-    MOZ_TRY(xdr->codeUint32(&uncompressedLength));
-
-    return ss->xdrUncompressedSource(xdr, sizeof(Unit), uncompressedLength);
-  };
-
   auto CodeBinASTData = [xdr
 #if defined(JS_BUILD_BINAST)
                          ,
                          ss
 #endif
   ]() -> XDRResult {
 #if !defined(JS_BUILD_BINAST)
     return xdr->fail(JS::TranscodeResult_Throw);
@@ -2927,26 +2931,24 @@ XDRResult ScriptSource::xdrData(XDRState
   };
 
   switch (tag) {
     case DataType::CompressedUtf8:
       // The argument here is just for overloading -- its value doesn't matter.
       return CodeCompressedData(Utf8Unit('0'));
 
     case DataType::UncompressedUtf8:
-      // The argument here is just for overloading -- its value doesn't matter.
-      return CodeUncompressedData(Utf8Unit('0'));
+      return ScriptSource::codeUncompressedData<Utf8Unit>(xdr, ss, retrievable);
 
     case DataType::CompressedUtf16:
       // The argument here is just for overloading -- its value doesn't matter.
       return CodeCompressedData(char16_t('0'));
 
     case DataType::UncompressedUtf16:
-      // The argument here is just for overloading -- its value doesn't matter.
-      return CodeUncompressedData(char16_t('0'));
+      return ScriptSource::codeUncompressedData<char16_t>(xdr, ss, retrievable);
 
     case DataType::Missing: {
       MOZ_ASSERT(ss->data.is<Missing>(),
                  "ScriptSource::data is initialized as missing, so neither "
                  "encoding nor decoding has to change anything");
 
       // There's no data to XDR for missing source.
       break;
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -1141,16 +1141,21 @@ class ScriptSource {
   const mozilla::TimeStamp parseEnded() const { return parseEnded_; }
   // Inform `this` source that it has been fully parsed.
   void recordParseEnded() {
     MOZ_ASSERT(parseEnded_.IsNull());
     parseEnded_ = ReallyNow();
   }
 
  private:
+  template <typename Unit, XDRMode mode>
+  static MOZ_MUST_USE XDRResult codeUncompressedData(XDRState<mode>* const xdr,
+                                                     ScriptSource* const ss,
+                                                     bool retrievable);
+
   template <XDRMode mode>
   static MOZ_MUST_USE XDRResult xdrData(XDRState<mode>* const xdr,
                                         ScriptSource* const ss);
 
  public:
   template <XDRMode mode>
   static MOZ_MUST_USE XDRResult
   XDR(XDRState<mode>* xdr, const mozilla::Maybe<JS::CompileOptions>& options,