mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1674045 - UniqueJSONStrings takes string spans instead of pointers - r=gregtatum
For consistency with `JSONWriter` (which UniqueJSONStrings' functions use), and for added safety and some efficiency, UniqueJSONStrings now takes `Span<const char`> arguments instead of raw pointers to null-terminated strings. Differential Revision: https://phabricator.services.mozilla.com/D95114
This commit is contained in:
parent
c68a3c6b21
commit
9acb23c062
@ -183,7 +183,7 @@ class MOZ_RAII AutoArraySchemaWithStringsWriter : public AutoArraySchemaWriter {
|
||||
UniqueJSONStrings& aStrings)
|
||||
: AutoArraySchemaWriter(aWriter), mStrings(aStrings) {}
|
||||
|
||||
void StringElement(uint32_t aIndex, const char* aValue) {
|
||||
void StringElement(uint32_t aIndex, const Span<const char>& aValue) {
|
||||
FillUpTo(aIndex);
|
||||
mStrings.WriteElement(Writer(), aValue);
|
||||
}
|
||||
@ -279,7 +279,7 @@ void UniqueStacks::StreamNonJITFrame(const FrameKey& aFrame) {
|
||||
AutoArraySchemaWithStringsWriter writer(mFrameTableWriter, *mUniqueStrings);
|
||||
|
||||
const NormalFrameData& data = aFrame.mData.as<NormalFrameData>();
|
||||
writer.StringElement(LOCATION, data.mLocation.c_str());
|
||||
writer.StringElement(LOCATION, data.mLocation);
|
||||
writer.BoolElement(RELEVANT_FOR_JS, data.mRelevantForJS);
|
||||
|
||||
// It's okay to convert uint64_t to double here because DOM always creates IDs
|
||||
@ -789,8 +789,7 @@ void ProfileBuffer::StreamMarkersToJSON(SpliceableJSONWriter& aWriter,
|
||||
!::mozilla::base_profiler_markers_detail::DeserializeAfterKindAndStream(
|
||||
aER, aWriter, aThreadId,
|
||||
[&](const mozilla::ProfilerString8View& aName) {
|
||||
aUniqueStacks.mUniqueStrings->WriteElement(
|
||||
aWriter, aName.String().c_str());
|
||||
aUniqueStacks.mUniqueStrings->WriteElement(aWriter, aName);
|
||||
},
|
||||
[&](ProfileChunkedBuffer& aChunkedBuffer) {
|
||||
ProfilerBacktrace backtrace("", &aChunkedBuffer);
|
||||
|
@ -32,9 +32,9 @@ void UniqueJSONStrings::SpliceStringTableElements(
|
||||
aWriter.TakeAndSplice(mStringTableWriter.TakeChunkedWriteFunc());
|
||||
}
|
||||
|
||||
uint32_t UniqueJSONStrings::GetOrAddIndex(const char* aStr) {
|
||||
uint32_t UniqueJSONStrings::GetOrAddIndex(const Span<const char>& aStr) {
|
||||
uint32_t count = mStringHashToIndexMap.count();
|
||||
HashNumber hash = HashString(aStr);
|
||||
HashNumber hash = HashString(aStr.data(), aStr.size());
|
||||
auto entry = mStringHashToIndexMap.lookupForAdd(hash);
|
||||
if (entry) {
|
||||
MOZ_ASSERT(entry->value() < count);
|
||||
@ -42,7 +42,7 @@ uint32_t UniqueJSONStrings::GetOrAddIndex(const char* aStr) {
|
||||
}
|
||||
|
||||
MOZ_RELEASE_ASSERT(mStringHashToIndexMap.add(entry, hash, count));
|
||||
mStringTableWriter.StringElement(MakeStringSpan(aStr));
|
||||
mStringTableWriter.StringElement(aStr);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
@ -306,13 +306,14 @@ class UniqueJSONStrings {
|
||||
|
||||
// Add `aStr` to the list (if not already there), and write its index as a
|
||||
// named object property.
|
||||
void WriteProperty(JSONWriter& aWriter, const char* aName, const char* aStr) {
|
||||
aWriter.IntProperty(MakeStringSpan(aName), GetOrAddIndex(aStr));
|
||||
void WriteProperty(JSONWriter& aWriter, const Span<const char>& aName,
|
||||
const Span<const char>& aStr) {
|
||||
aWriter.IntProperty(aName, GetOrAddIndex(aStr));
|
||||
}
|
||||
|
||||
// Add `aStr` to the list (if not already there), and write its index as an
|
||||
// array element.
|
||||
void WriteElement(JSONWriter& aWriter, const char* aStr) {
|
||||
void WriteElement(JSONWriter& aWriter, const Span<const char>& aStr) {
|
||||
aWriter.IntElement(GetOrAddIndex(aStr));
|
||||
}
|
||||
|
||||
@ -323,7 +324,7 @@ class UniqueJSONStrings {
|
||||
private:
|
||||
// If `aStr` is already listed, return its index.
|
||||
// Otherwise add it to the list and return the new index.
|
||||
MFBT_API uint32_t GetOrAddIndex(const char* aStr);
|
||||
MFBT_API uint32_t GetOrAddIndex(const Span<const char>& aStr);
|
||||
|
||||
SpliceableChunkedJSONWriter mStringTableWriter;
|
||||
HashMap<HashNumber, uint32_t> mStringHashToIndexMap;
|
||||
|
@ -196,7 +196,7 @@ class MOZ_RAII AutoArraySchemaWithStringsWriter : public AutoArraySchemaWriter {
|
||||
UniqueJSONStrings& aStrings)
|
||||
: AutoArraySchemaWriter(aWriter), mStrings(aStrings) {}
|
||||
|
||||
void StringElement(uint32_t aIndex, const char* aValue) {
|
||||
void StringElement(uint32_t aIndex, const Span<const char>& aValue) {
|
||||
FillUpTo(aIndex);
|
||||
mStrings.WriteElement(Writer(), aValue);
|
||||
}
|
||||
@ -384,7 +384,7 @@ void UniqueStacks::StreamNonJITFrame(const FrameKey& aFrame) {
|
||||
AutoArraySchemaWithStringsWriter writer(mFrameTableWriter, *mUniqueStrings);
|
||||
|
||||
const NormalFrameData& data = aFrame.mData.as<NormalFrameData>();
|
||||
writer.StringElement(LOCATION, data.mLocation.get());
|
||||
writer.StringElement(LOCATION, data.mLocation);
|
||||
writer.BoolElement(RELEVANT_FOR_JS, data.mRelevantForJS);
|
||||
|
||||
// It's okay to convert uint64_t to double here because DOM always creates IDs
|
||||
@ -394,7 +394,7 @@ void UniqueStacks::StreamNonJITFrame(const FrameKey& aFrame) {
|
||||
// The C++ interpreter is the default implementation so we only emit element
|
||||
// for Baseline Interpreter frames.
|
||||
if (data.mBaselineInterp) {
|
||||
writer.StringElement(IMPLEMENTATION, "blinterp");
|
||||
writer.StringElement(IMPLEMENTATION, MakeStringSpan("blinterp"));
|
||||
}
|
||||
|
||||
if (data.mLine.isSome()) {
|
||||
@ -428,7 +428,7 @@ static void StreamJITFrame(JSContext* aContext, SpliceableJSONWriter& aWriter,
|
||||
|
||||
AutoArraySchemaWithStringsWriter writer(aWriter, aUniqueStrings);
|
||||
|
||||
writer.StringElement(LOCATION, aJITFrame.label());
|
||||
writer.StringElement(LOCATION, MakeStringSpan(aJITFrame.label()));
|
||||
writer.BoolElement(RELEVANT_FOR_JS, false);
|
||||
|
||||
// It's okay to convert uint64_t to double here because DOM always creates IDs
|
||||
@ -439,9 +439,10 @@ static void StreamJITFrame(JSContext* aContext, SpliceableJSONWriter& aWriter,
|
||||
JS::ProfilingFrameIterator::FrameKind frameKind = aJITFrame.frameKind();
|
||||
MOZ_ASSERT(frameKind == JS::ProfilingFrameIterator::Frame_Ion ||
|
||||
frameKind == JS::ProfilingFrameIterator::Frame_Baseline);
|
||||
writer.StringElement(
|
||||
IMPLEMENTATION,
|
||||
frameKind == JS::ProfilingFrameIterator::Frame_Ion ? "ion" : "baseline");
|
||||
writer.StringElement(IMPLEMENTATION,
|
||||
frameKind == JS::ProfilingFrameIterator::Frame_Ion
|
||||
? MakeStringSpan("ion")
|
||||
: MakeStringSpan("baseline"));
|
||||
|
||||
const JS::ProfilingCategoryPairInfo& info = JS::GetProfilingCategoryPairInfo(
|
||||
frameKind == JS::ProfilingFrameIterator::Frame_Ion
|
||||
@ -1191,7 +1192,7 @@ void ProfileBuffer::StreamMarkersToJSON(SpliceableJSONWriter& aWriter,
|
||||
|
||||
// Now write this information to JSON with the following schema:
|
||||
// [name, startTime, endTime, phase, category, data]
|
||||
aUniqueStacks.mUniqueStrings->WriteElement(aWriter, name.c_str());
|
||||
aUniqueStacks.mUniqueStrings->WriteElement(aWriter, name);
|
||||
aWriter.DoubleElement(startTime);
|
||||
aWriter.DoubleElement(endTime);
|
||||
aWriter.IntElement(phase);
|
||||
@ -1212,8 +1213,8 @@ void ProfileBuffer::StreamMarkersToJSON(SpliceableJSONWriter& aWriter,
|
||||
DeserializeAfterKindAndStream(
|
||||
aER, aWriter, aThreadId,
|
||||
[&](const mozilla::ProfilerString8View& aName) {
|
||||
aUniqueStacks.mUniqueStrings->WriteElement(
|
||||
aWriter, aName.String().c_str());
|
||||
aUniqueStacks.mUniqueStrings->WriteElement(aWriter,
|
||||
aName);
|
||||
},
|
||||
[&](ProfileChunkedBuffer& aChunkedBuffer) {
|
||||
ProfilerBacktrace backtrace("", &aChunkedBuffer);
|
||||
|
@ -705,8 +705,8 @@ void ScreenshotPayload::StreamPayload(SpliceableJSONWriter& aWriter,
|
||||
const TimeStamp& aProcessStartTime,
|
||||
UniqueStacks& aUniqueStacks) const {
|
||||
StreamType("CompositorScreenshot", aWriter);
|
||||
aUniqueStacks.mUniqueStrings->WriteProperty(aWriter, "url",
|
||||
mScreenshotDataURL.get());
|
||||
aUniqueStacks.mUniqueStrings->WriteProperty(aWriter, MakeStringSpan("url"),
|
||||
mScreenshotDataURL);
|
||||
|
||||
char hexWindowID[32];
|
||||
const int written =
|
||||
|
Loading…
Reference in New Issue
Block a user