Bug 1469305 - avoid useless copies for GC statistics notifications; r=mccr8

std::move'ing the string here enables us to avoid a useless copy of the
string.  Normally this would be just a refcounting increment/decrement,
but since we've Adopt'd the string a couple of lines earlier and the
incoming string is therefore just an owned character buffer, rather than
a refcounted character buffer, the copy here is a "real" copy.

What would be ideal here is to pass the (un-JSON'd) GCDescription out to
the notification, so we don't even have to render and parse JSON, but
that can be left for a later day.
This commit is contained in:
Nathan Froyd 2018-06-18 11:47:09 -04:00
parent d208c9613c
commit 058d0bf372

View File

@ -2263,9 +2263,9 @@ class NotifyGCEndRunnable : public Runnable
nsString mMessage;
public:
explicit NotifyGCEndRunnable(const nsString& aMessage)
explicit NotifyGCEndRunnable(nsString&& aMessage)
: mozilla::Runnable("NotifyGCEndRunnable")
, mMessage(aMessage)
, mMessage(std::move(aMessage))
{
}
@ -2323,7 +2323,7 @@ DOMGCSliceCallback(JSContext* aCx, JS::GCProgress aProgress, const JS::GCDescrip
Telemetry::CanRecordExtended()) {
nsString json;
json.Adopt(aDesc.formatJSON(aCx, PR_Now()));
RefPtr<NotifyGCEndRunnable> notify = new NotifyGCEndRunnable(json);
RefPtr<NotifyGCEndRunnable> notify = new NotifyGCEndRunnable(std::move(json));
SystemGroup::Dispatch(TaskCategory::GarbageCollection, notify.forget());
}
}