Bug 1434965 - Remove AutoArraySchemaWriter constructor that doesn't take a string table. r?njn
WriteSamples doesn't really need the ability to write strings, but always passing
a string table means that there's one less thing to worry about (one less piece of
unsafe API).
MozReview-Commit-ID: 386OEibyush
--- a/tools/profiler/core/ProfileBufferEntry.cpp
+++ b/tools/profiler/core/ProfileBufferEntry.cpp
@@ -174,33 +174,23 @@ public:
// writer.IntElement(FOO, getFoo());
// }
// ... etc ...
class MOZ_RAII AutoArraySchemaWriter
{
friend class AutoObjectWriter;
SpliceableJSONWriter& mJSONWriter;
- UniqueJSONStrings* mStrings;
+ UniqueJSONStrings& mStrings;
uint32_t mNextFreeIndex;
public:
AutoArraySchemaWriter(SpliceableJSONWriter& aWriter, UniqueJSONStrings& aStrings)
: mJSONWriter(aWriter)
- , mStrings(&aStrings)
- , mNextFreeIndex(0)
- {
- mJSONWriter.StartArrayElement(SpliceableJSONWriter::SingleLineStyle);
- }
-
- // If you don't have access to a UniqueStrings, you had better not try and
- // write a string element down the line!
- explicit AutoArraySchemaWriter(SpliceableJSONWriter& aWriter)
- : mJSONWriter(aWriter)
- , mStrings(nullptr)
+ , mStrings(aStrings)
, mNextFreeIndex(0)
{
mJSONWriter.StartArrayElement(SpliceableJSONWriter::SingleLineStyle);
}
~AutoArraySchemaWriter() {
mJSONWriter.EndArray();
}
@@ -217,19 +207,18 @@ public:
}
void DoubleElement(uint32_t aIndex, double aValue) {
FillUpTo(aIndex);
mJSONWriter.DoubleElement(aValue);
}
void StringElement(uint32_t aIndex, const char* aValue) {
- MOZ_RELEASE_ASSERT(mStrings);
FillUpTo(aIndex);
- mStrings->WriteElement(mJSONWriter, aValue);
+ mStrings.WriteElement(mJSONWriter, aValue);
}
};
class StreamOptimizationAttemptsOp : public JS::ForEachTrackedOptimizationAttemptOp
{
SpliceableJSONWriter& mWriter;
UniqueJSONStrings& mUniqueStrings;
@@ -503,27 +492,29 @@ struct ProfileSample
{
uint32_t mStack;
double mTime;
Maybe<double> mResponsiveness;
Maybe<double> mRSS;
Maybe<double> mUSS;
};
-static void WriteSample(SpliceableJSONWriter& aWriter, ProfileSample& aSample)
+static void
+WriteSample(SpliceableJSONWriter& aWriter, UniqueJSONStrings& aUniqueStrings,
+ const ProfileSample& aSample)
{
enum Schema : uint32_t {
STACK = 0,
TIME = 1,
RESPONSIVENESS = 2,
RSS = 3,
USS = 4
};
- AutoArraySchemaWriter writer(aWriter);
+ AutoArraySchemaWriter writer(aWriter, aUniqueStrings);
writer.IntElement(STACK, aSample.mStack);
writer.DoubleElement(TIME, aSample.mTime);
if (aSample.mResponsiveness.isSome()) {
writer.DoubleElement(RESPONSIVENESS, *aSample.mResponsiveness);
}
@@ -854,17 +845,17 @@ ProfileBuffer::StreamSamplesToJSON(Splic
e.Next();
}
if (e.Has() && e.Get().IsUnsharedMemory()) {
sample.mUSS = Some(e.Get().u.mDouble);
e.Next();
}
- WriteSample(aWriter, sample);
+ WriteSample(aWriter, aUniqueStacks.mUniqueStrings, sample);
haveSamples = true;
}
return haveSamples;
#undef ERROR_AND_CONTINUE
}
// This method returns true if it wrote anything to the writer.