зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1271407 - Remove unnecessary methods from `js::ScriptSource`; r=luke
This commit removes the following methods from `js::ScriptSource`: * `compressedChars` * `compressedBytes` * `uncompressedChars` They are throwbacks from when `ScriptSource` had this big, hand-rolled tagged union, and these methods were getters that did all sanity asserts on the tag state. That union has since been replaced with a `mozilla::Variant`, so we should just use `mozilla::Variant`'s type-safe accessors instead.
This commit is contained in:
Родитель
7b5fd55b61
Коммит
8031f0ba5c
|
@ -1884,8 +1884,8 @@ ScriptSource::sourceText(JSContext* cx)
|
|||
return mozilla::Nothing();
|
||||
}
|
||||
|
||||
if (!DecompressString((const unsigned char*) ss.compressedData(),
|
||||
ss.compressedBytes(),
|
||||
if (!DecompressString((const unsigned char*) c.raw.chars(),
|
||||
c.raw.length(),
|
||||
reinterpret_cast<unsigned char*>(decompressed.get()),
|
||||
lengthWithNull * sizeof(char16_t)))
|
||||
{
|
||||
|
@ -2051,6 +2051,8 @@ ScriptSource::setSourceCopy(ExclusiveContext* cx, SourceBufferHolder& srcBuf,
|
|||
SourceCompressionTask::ResultType
|
||||
SourceCompressionTask::work()
|
||||
{
|
||||
MOZ_ASSERT(ss->data.is<ScriptSource::Uncompressed>());
|
||||
|
||||
// Try to keep the maximum memory usage down by only allocating half the
|
||||
// size of the string, first.
|
||||
size_t inputBytes = ss->length() * sizeof(char16_t);
|
||||
|
@ -2059,7 +2061,9 @@ SourceCompressionTask::work()
|
|||
if (!compressed)
|
||||
return OOM;
|
||||
|
||||
Compressor comp(reinterpret_cast<const unsigned char*>(ss->uncompressedChars()), inputBytes);
|
||||
const char16_t* chars = ss->data.as<ScriptSource::Uncompressed>().string.chars();
|
||||
Compressor comp(reinterpret_cast<const unsigned char*>(chars),
|
||||
inputBytes);
|
||||
if (!comp.init())
|
||||
return OOM;
|
||||
|
||||
|
@ -2127,7 +2131,7 @@ ScriptSource::performXDR(XDRState<mode>* xdr)
|
|||
}
|
||||
|
||||
ReturnType match(Compressed& c) {
|
||||
return c.nbytes();
|
||||
return c.raw.length();
|
||||
}
|
||||
|
||||
ReturnType match(Missing&) {
|
||||
|
|
|
@ -620,14 +620,12 @@ class ScriptSource
|
|||
struct Compressed
|
||||
{
|
||||
SharedImmutableString raw;
|
||||
size_t length;
|
||||
size_t uncompressedLength;
|
||||
|
||||
Compressed(SharedImmutableString&& raw, size_t length)
|
||||
Compressed(SharedImmutableString&& raw, size_t uncompressedLength)
|
||||
: raw(mozilla::Move(raw))
|
||||
, length(length)
|
||||
, uncompressedLength(uncompressedLength)
|
||||
{ }
|
||||
|
||||
size_t nbytes() const { return raw.length(); }
|
||||
};
|
||||
|
||||
using SourceType = mozilla::Variant<Missing, Uncompressed, Compressed>;
|
||||
|
@ -724,7 +722,7 @@ class ScriptSource
|
|||
}
|
||||
|
||||
ReturnType match(const Compressed& c) {
|
||||
return c.length;
|
||||
return c.uncompressedLength;
|
||||
}
|
||||
|
||||
ReturnType match(const Missing& m) {
|
||||
|
@ -751,18 +749,6 @@ class ScriptSource
|
|||
void addSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf,
|
||||
JS::ScriptSourceInfo* info) const;
|
||||
|
||||
const char16_t* uncompressedChars() const {
|
||||
return data.as<Uncompressed>().string.chars();
|
||||
}
|
||||
|
||||
const void* compressedData() const {
|
||||
return static_cast<const void*>(data.as<Compressed>().raw.chars());
|
||||
}
|
||||
|
||||
size_t compressedBytes() const {
|
||||
return data.as<Compressed>().nbytes();
|
||||
}
|
||||
|
||||
MOZ_MUST_USE bool setSource(ExclusiveContext* cx,
|
||||
mozilla::UniquePtr<char16_t[], JS::FreePolicy>&& source,
|
||||
size_t length);
|
||||
|
|
Загрузка…
Ссылка в новой задаче