Bug 1499507 - Use AppendPrintf to concatenate the label with the dynamic string. r=njn

This code is run during JSON serialization so performance is not a big concern.

Depends on D9195

Differential Revision: https://phabricator.services.mozilla.com/D9197

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Markus Stange 2018-11-06 04:31:45 +00:00
Родитель ab700f9fc0
Коммит 974ec0a838
2 изменённых файлов: 20 добавлений и 21 удалений

Просмотреть файл

@ -949,7 +949,7 @@ ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThreadId,
double aSinceTime,
UniqueStacks& aUniqueStacks) const
{
UniquePtr<char[]> strbuf = MakeUnique<char[]>(kMaxFrameKeyLength);
UniquePtr<char[]> dynStrBuf = MakeUnique<char[]>(kMaxFrameKeyLength);
EntryGetter e(*this);
@ -1024,30 +1024,20 @@ ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThreadId,
} else if (e.Get().IsLabel()) {
numFrames++;
// Copy the label into strbuf.
const char* label = e.Get().u.mString;
strncpy(strbuf.get(), label, kMaxFrameKeyLength);
size_t i = strlen(label);
e.Next();
bool seenFirstDynamicStringFragment = false;
// Copy potential dynamic string fragments into dynStrBuf, so that
// dynStrBuf will then contain the entire dynamic string.
size_t i = 0;
dynStrBuf[0] = '\0';
while (e.Has()) {
if (e.Get().IsDynamicStringFragment()) {
// If this is the first dynamic string fragment and we have a
// non-empty label, insert a ' ' after the label and before the
// dynamic string.
if (!seenFirstDynamicStringFragment) {
if (i > 0 && i < kMaxFrameKeyLength) {
strbuf[i] = ' ';
i++;
}
seenFirstDynamicStringFragment = true;
}
for (size_t j = 0; j < ProfileBufferEntry::kNumChars; j++) {
const char* chars = e.Get().u.mChars;
if (i < kMaxFrameKeyLength) {
strbuf[i] = chars[j];
dynStrBuf[i] = chars[j];
i++;
}
}
@ -1056,7 +1046,15 @@ ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThreadId,
break;
}
}
strbuf[kMaxFrameKeyLength - 1] = '\0';
dynStrBuf[kMaxFrameKeyLength - 1] = '\0';
bool hasDynamicString = (i != 0);
nsCString frameLabel;
if (label[0] != '\0' && hasDynamicString) {
frameLabel.AppendPrintf("%s %s", label, dynStrBuf.get());
} else {
frameLabel.Append(label);
}
Maybe<unsigned> line;
if (e.Has() && e.Get().IsLineNumber()) {
@ -1077,7 +1075,8 @@ ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThreadId,
}
stack = aUniqueStacks.AppendFrame(
stack, UniqueStacks::FrameKey(strbuf.get(), line, column, category));
stack, UniqueStacks::FrameKey(std::move(frameLabel), line, column,
category));
} else if (e.Get().IsJitReturnAddr()) {
numFrames++;

Просмотреть файл

@ -235,10 +235,10 @@ public:
{
}
FrameKey(const char* aLocation, const mozilla::Maybe<unsigned>& aLine,
FrameKey(nsCString&& aLocation, const mozilla::Maybe<unsigned>& aLine,
const mozilla::Maybe<unsigned>& aColumn,
const mozilla::Maybe<unsigned>& aCategory)
: mData(NormalFrameData{ nsCString(aLocation), aLine, aColumn, aCategory })
: mData(NormalFrameData{ aLocation, aLine, aColumn, aCategory })
{
}