mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1388253 - Convert nsTextFormatter:[v]smprintf() use to [v]ssprintf(). r=erahm.
[v]ssprintf() is just a better way of doing things. --HG-- extra : rebase_source : 25337787b9557f8a7080a67645dba70609a8f646
This commit is contained in:
parent
5ae793d1a7
commit
d4e19d954a
@ -1687,21 +1687,21 @@ nsJSContext::EndCycleCollectionCallback(CycleCollectorResults &aResults)
|
||||
u"CC(T+%.1f)[%s-%i] max pause: %lums, total time: %lums, slices: %lu, suspected: %lu, visited: %lu RCed and %lu%s GCed, collected: %lu RCed and %lu GCed (%lu|%lu|%lu waiting for GC)%s\n"
|
||||
u"ForgetSkippable %lu times before CC, min: %lu ms, max: %lu ms, avg: %lu ms, total: %lu ms, max sync: %lu ms, removed: %lu";
|
||||
nsString msg;
|
||||
msg.Adopt(nsTextFormatter::smprintf(kFmt, double(delta) / PR_USEC_PER_SEC,
|
||||
ProcessNameForCollectorLog(), getpid(),
|
||||
gCCStats.mMaxSliceTime, gCCStats.mTotalSliceTime,
|
||||
aResults.mNumSlices, gCCStats.mSuspected,
|
||||
aResults.mVisitedRefCounted, aResults.mVisitedGCed, mergeMsg.get(),
|
||||
aResults.mFreedRefCounted, aResults.mFreedGCed,
|
||||
sCCollectedWaitingForGC, sCCollectedZonesWaitingForGC, sLikelyShortLivingObjectsNeedingGC,
|
||||
gcMsg.get(),
|
||||
sForgetSkippableBeforeCC,
|
||||
minForgetSkippableTime / PR_USEC_PER_MSEC,
|
||||
sMaxForgetSkippableTime / PR_USEC_PER_MSEC,
|
||||
(sTotalForgetSkippableTime / cleanups) /
|
||||
PR_USEC_PER_MSEC,
|
||||
sTotalForgetSkippableTime / PR_USEC_PER_MSEC,
|
||||
gCCStats.mMaxSkippableDuration, sRemovedPurples));
|
||||
nsTextFormatter::ssprintf(msg, kFmt, double(delta) / PR_USEC_PER_SEC,
|
||||
ProcessNameForCollectorLog(), getpid(),
|
||||
gCCStats.mMaxSliceTime, gCCStats.mTotalSliceTime,
|
||||
aResults.mNumSlices, gCCStats.mSuspected,
|
||||
aResults.mVisitedRefCounted, aResults.mVisitedGCed, mergeMsg.get(),
|
||||
aResults.mFreedRefCounted, aResults.mFreedGCed,
|
||||
sCCollectedWaitingForGC, sCCollectedZonesWaitingForGC, sLikelyShortLivingObjectsNeedingGC,
|
||||
gcMsg.get(),
|
||||
sForgetSkippableBeforeCC,
|
||||
minForgetSkippableTime / PR_USEC_PER_MSEC,
|
||||
sMaxForgetSkippableTime / PR_USEC_PER_MSEC,
|
||||
(sTotalForgetSkippableTime / cleanups) /
|
||||
PR_USEC_PER_MSEC,
|
||||
sTotalForgetSkippableTime / PR_USEC_PER_MSEC,
|
||||
gCCStats.mMaxSkippableDuration, sRemovedPurples);
|
||||
if (sPostGCEventsToConsole) {
|
||||
nsCOMPtr<nsIConsoleService> cs =
|
||||
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
||||
@ -1741,27 +1741,27 @@ nsJSContext::EndCycleCollectionCallback(CycleCollectorResults &aResults)
|
||||
u"\"total\": %lu, "
|
||||
u"\"removed\": %lu } "
|
||||
u"}";
|
||||
nsString json;
|
||||
|
||||
json.Adopt(nsTextFormatter::smprintf(kJSONFmt, PR_Now(), ccNowDuration,
|
||||
gCCStats.mMaxSliceTime,
|
||||
gCCStats.mTotalSliceTime,
|
||||
gCCStats.mMaxGCDuration,
|
||||
gCCStats.mMaxSkippableDuration,
|
||||
gCCStats.mSuspected,
|
||||
aResults.mVisitedRefCounted, aResults.mVisitedGCed,
|
||||
aResults.mFreedRefCounted, aResults.mFreedGCed,
|
||||
sCCollectedWaitingForGC,
|
||||
sCCollectedZonesWaitingForGC,
|
||||
sLikelyShortLivingObjectsNeedingGC,
|
||||
aResults.mForcedGC,
|
||||
sForgetSkippableBeforeCC,
|
||||
minForgetSkippableTime / PR_USEC_PER_MSEC,
|
||||
sMaxForgetSkippableTime / PR_USEC_PER_MSEC,
|
||||
(sTotalForgetSkippableTime / cleanups) /
|
||||
PR_USEC_PER_MSEC,
|
||||
sTotalForgetSkippableTime / PR_USEC_PER_MSEC,
|
||||
sRemovedPurples));
|
||||
nsString json;
|
||||
nsTextFormatter::ssprintf(json, kJSONFmt, PR_Now(), ccNowDuration,
|
||||
gCCStats.mMaxSliceTime,
|
||||
gCCStats.mTotalSliceTime,
|
||||
gCCStats.mMaxGCDuration,
|
||||
gCCStats.mMaxSkippableDuration,
|
||||
gCCStats.mSuspected,
|
||||
aResults.mVisitedRefCounted, aResults.mVisitedGCed,
|
||||
aResults.mFreedRefCounted, aResults.mFreedGCed,
|
||||
sCCollectedWaitingForGC,
|
||||
sCCollectedZonesWaitingForGC,
|
||||
sLikelyShortLivingObjectsNeedingGC,
|
||||
aResults.mForcedGC,
|
||||
sForgetSkippableBeforeCC,
|
||||
minForgetSkippableTime / PR_USEC_PER_MSEC,
|
||||
sMaxForgetSkippableTime / PR_USEC_PER_MSEC,
|
||||
(sTotalForgetSkippableTime / cleanups) /
|
||||
PR_USEC_PER_MSEC,
|
||||
sTotalForgetSkippableTime / PR_USEC_PER_MSEC,
|
||||
sRemovedPurples);
|
||||
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
||||
if (observerService) {
|
||||
observerService->NotifyObservers(nullptr, "cycle-collection-statistics", json.get());
|
||||
@ -2253,12 +2253,12 @@ DOMGCSliceCallback(JSContext* aCx, JS::GCProgress aProgress, const JS::GCDescrip
|
||||
PRTime delta = GetCollectionTimeDelta();
|
||||
|
||||
if (sPostGCEventsToConsole) {
|
||||
nsString prefix, gcstats;
|
||||
nsString gcstats;
|
||||
gcstats.Adopt(aDesc.formatSummaryMessage(aCx));
|
||||
prefix.Adopt(nsTextFormatter::smprintf(u"GC(T+%.1f)[%s-%i] ",
|
||||
double(delta) / PR_USEC_PER_SEC,
|
||||
ProcessNameForCollectorLog(),
|
||||
getpid()));
|
||||
nsAutoString prefix;
|
||||
nsTextFormatter::ssprintf(prefix, u"GC(T+%.1f)[%s-%i] ",
|
||||
double(delta) / PR_USEC_PER_SEC,
|
||||
ProcessNameForCollectorLog(), getpid());
|
||||
nsString msg = prefix + gcstats;
|
||||
nsCOMPtr<nsIConsoleService> cs = do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
||||
if (cs) {
|
||||
@ -2339,11 +2339,11 @@ DOMGCSliceCallback(JSContext* aCx, JS::GCProgress aProgress, const JS::GCDescrip
|
||||
}
|
||||
|
||||
if (sPostGCEventsToConsole) {
|
||||
nsString prefix, gcstats;
|
||||
nsString gcstats;
|
||||
gcstats.Adopt(aDesc.formatSliceMessage(aCx));
|
||||
prefix.Adopt(nsTextFormatter::smprintf(u"[%s-%i] ",
|
||||
ProcessNameForCollectorLog(),
|
||||
getpid()));
|
||||
nsAutoString prefix;
|
||||
nsTextFormatter::ssprintf(prefix, u"[%s-%i] ",
|
||||
ProcessNameForCollectorLog(), getpid());
|
||||
nsString msg = prefix + gcstats;
|
||||
nsCOMPtr<nsIConsoleService> cs = do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
||||
if (cs) {
|
||||
|
@ -33,11 +33,11 @@ interface nsIStringBundle : nsISupports
|
||||
[noscript, binaryname(GetStringFromName)]
|
||||
AString GetStringFromNameCpp(in string aName);
|
||||
|
||||
// this is kind of like smprintf - except that you can
|
||||
// this is kind of like ssprintf - except that you can
|
||||
// only pass it unicode strings, using the %S formatting character.
|
||||
// the id or name should refer to a string in the bundle that
|
||||
// uses %S.. do NOT try to use any other types.
|
||||
// this uses nsTextFormatter::smprintf to do the dirty work.
|
||||
// this uses nsTextFormatter::ssprintf to do the dirty work.
|
||||
AString formatStringFromID(in long aID,
|
||||
[array, size_is(length)] in wstring params,
|
||||
in unsigned long length);
|
||||
|
@ -197,18 +197,19 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
||||
// values
|
||||
NS_NAMED_LITERAL_STRING(kPageAndTotal, "&PT");
|
||||
if (aStr.Find(kPageAndTotal) != kNotFound) {
|
||||
char16_t * uStr = nsTextFormatter::smprintf(mPD->mPageNumAndTotalsFormat.get(), mPageNum, mTotNumPages);
|
||||
aNewStr.ReplaceSubstring(kPageAndTotal, nsDependentString(uStr));
|
||||
free(uStr);
|
||||
nsAutoString uStr;
|
||||
nsTextFormatter::ssprintf(uStr, mPD->mPageNumAndTotalsFormat.get(),
|
||||
mPageNum, mTotNumPages);
|
||||
aNewStr.ReplaceSubstring(kPageAndTotal, uStr);
|
||||
}
|
||||
|
||||
// Search to see if the page number code is in the string
|
||||
// and replace the page number code with the actual value
|
||||
NS_NAMED_LITERAL_STRING(kPage, "&P");
|
||||
if (aStr.Find(kPage) != kNotFound) {
|
||||
char16_t * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat.get(), mPageNum);
|
||||
aNewStr.ReplaceSubstring(kPage, nsDependentString(uStr));
|
||||
free(uStr);
|
||||
nsAutoString uStr;
|
||||
nsTextFormatter::ssprintf(uStr, mPD->mPageNumFormat.get(), mPageNum);
|
||||
aNewStr.ReplaceSubstring(kPage, uStr);
|
||||
}
|
||||
|
||||
NS_NAMED_LITERAL_STRING(kTitle, "&T");
|
||||
@ -223,9 +224,9 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
||||
|
||||
NS_NAMED_LITERAL_STRING(kPageTotal, "&L");
|
||||
if (aStr.Find(kPageTotal) != kNotFound) {
|
||||
char16_t * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat.get(), mTotNumPages);
|
||||
aNewStr.ReplaceSubstring(kPageTotal, nsDependentString(uStr));
|
||||
free(uStr);
|
||||
nsAutoString uStr;
|
||||
nsTextFormatter::ssprintf(uStr, mPD->mPageNumFormat.get(), mTotNumPages);
|
||||
aNewStr.ReplaceSubstring(kPageTotal, uStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -827,16 +827,8 @@ CreateErrorText(const char16_t* aDescription,
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// XML Parsing Error: %1$S\nLocation: %2$S\nLine Number %3$u, Column %4$u:
|
||||
char16_t *message = nsTextFormatter::smprintf(msg.get(), aDescription,
|
||||
aSourceURL, aLineNumber,
|
||||
aColNumber);
|
||||
if (!message) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
aErrorString.Assign(message);
|
||||
free(message);
|
||||
|
||||
nsTextFormatter::ssprintf(aErrorString, msg.get(), aDescription,
|
||||
aSourceURL, aLineNumber, aColNumber);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -919,14 +911,9 @@ nsExpatDriver::HandleError()
|
||||
"Expected", msg);
|
||||
|
||||
// . Expected: </%S>.
|
||||
char16_t *message = nsTextFormatter::smprintf(msg.get(), tagName.get());
|
||||
if (!message) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsAutoString message;
|
||||
nsTextFormatter::ssprintf(message, msg.get(), tagName.get());
|
||||
description.Append(message);
|
||||
|
||||
free(message);
|
||||
}
|
||||
|
||||
// Adjust the column number so that it is one based rather than zero based.
|
||||
|
@ -488,14 +488,13 @@ LogConsoleMessage(const char16_t* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
char16_t* msg = nsTextFormatter::vsmprintf(fmt, args);
|
||||
nsString msg;
|
||||
nsTextFormatter::vssprintf(msg, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
nsCOMPtr<nsIConsoleService> cs = do_GetService("@mozilla.org/consoleservice;1");
|
||||
if (cs)
|
||||
cs->LogStringMessage(msg);
|
||||
|
||||
free(msg);
|
||||
cs->LogStringMessage(msg.get());
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -58,6 +58,10 @@ public:
|
||||
*/
|
||||
static char16_t* smprintf(const char16_t* aFmt, ...);
|
||||
|
||||
/*
|
||||
* sprintf into an existing nsAString, overwriting any contents it already
|
||||
* has. Infallible.
|
||||
*/
|
||||
static uint32_t ssprintf(nsAString& aOut, const char16_t* aFmt, ...);
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user