mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-01 13:57:32 +00:00
Bug 1660751 - Use bare const char* in HandleError signature to reduce size of calling code. r=dom-workers-and-storage-reviewers,janv
Not that this is deliberately de-optimizing performance: Now, the HandleError functions need to use the nsDependentCString constructor to determine the length of the literals at run-time, since that's lost. While passing that in addition would reduce the binary size wins again, and is not necessary, since this code is only called in error situations, which are not performance-critical. Differential Revision: https://phabricator.services.mozilla.com/D89148
This commit is contained in:
parent
ffb37d08c1
commit
ec62d45a35
9
dom/cache/CacheCommon.cpp
vendored
9
dom/cache/CacheCommon.cpp
vendored
@ -8,10 +8,11 @@
|
||||
|
||||
namespace mozilla::dom::cache {
|
||||
|
||||
void HandleError(const nsLiteralCString& aExpr,
|
||||
const nsLiteralCString& aSourceFile, int32_t aSourceLine) {
|
||||
mozilla::dom::quota::LogError(nsLiteralCString("Cache"), aExpr, aSourceFile,
|
||||
aSourceLine);
|
||||
void HandleError(const char* const aExpr, const char* const aSourceFile,
|
||||
const int32_t aSourceLine) {
|
||||
mozilla::dom::quota::LogError(nsLiteralCString("Cache"),
|
||||
nsDependentCString(aExpr),
|
||||
nsDependentCString(aSourceFile), aSourceLine);
|
||||
}
|
||||
|
||||
} // namespace mozilla::dom::cache
|
||||
|
3
dom/cache/CacheCommon.h
vendored
3
dom/cache/CacheCommon.h
vendored
@ -44,8 +44,7 @@
|
||||
namespace mozilla::dom::cache {
|
||||
|
||||
// See comment on mozilla::dom::quota::HandleError
|
||||
MOZ_NEVER_INLINE void HandleError(const nsLiteralCString& aExpr,
|
||||
const nsLiteralCString& aSourceFile,
|
||||
MOZ_NEVER_INLINE void HandleError(const char* aExpr, const char* aSourceFile,
|
||||
int32_t aSourceLine);
|
||||
|
||||
} // namespace mozilla::dom::cache
|
||||
|
@ -8,10 +8,11 @@
|
||||
|
||||
namespace mozilla::dom::indexedDB {
|
||||
|
||||
void HandleError(const nsLiteralCString& aExpr,
|
||||
const nsLiteralCString& aSourceFile, int32_t aSourceLine) {
|
||||
mozilla::dom::quota::LogError(nsLiteralCString("IndexedDB"), aExpr,
|
||||
aSourceFile, aSourceLine);
|
||||
void HandleError(const char* const aExpr, const char* const aSourceFile,
|
||||
const int32_t aSourceLine) {
|
||||
mozilla::dom::quota::LogError(nsLiteralCString("IndexedDB"),
|
||||
nsDependentCString(aExpr),
|
||||
nsDependentCString(aSourceFile), aSourceLine);
|
||||
}
|
||||
|
||||
} // namespace mozilla::dom::indexedDB
|
||||
|
@ -45,8 +45,7 @@
|
||||
namespace mozilla::dom::indexedDB {
|
||||
|
||||
// See comment on mozilla::dom::quota::HandleError
|
||||
MOZ_NEVER_INLINE void HandleError(const nsLiteralCString& aExpr,
|
||||
const nsLiteralCString& aSourceFile,
|
||||
MOZ_NEVER_INLINE void HandleError(const char* aExpr, const char* aSourceFile,
|
||||
int32_t aSourceLine);
|
||||
|
||||
} // namespace mozilla::dom::indexedDB
|
||||
|
@ -142,10 +142,11 @@ LogModule* GetLocalStorageLogger() { return gLogger; }
|
||||
|
||||
namespace localstorage {
|
||||
|
||||
void HandleError(const nsLiteralCString& aExpr,
|
||||
const nsLiteralCString& aSourceFile, int32_t aSourceLine) {
|
||||
mozilla::dom::quota::LogError(nsLiteralCString("LocalStorage"), aExpr,
|
||||
aSourceFile, aSourceLine);
|
||||
void HandleError(const char* const aExpr, const char* const aSourceFile,
|
||||
const int32_t aSourceLine) {
|
||||
mozilla::dom::quota::LogError(nsLiteralCString("LocalStorage"),
|
||||
nsDependentCString(aExpr),
|
||||
nsDependentCString(aSourceFile), aSourceLine);
|
||||
}
|
||||
|
||||
} // namespace localstorage
|
||||
|
@ -282,8 +282,7 @@ LogModule* GetLocalStorageLogger();
|
||||
namespace localstorage {
|
||||
|
||||
// See comment on mozilla::dom::quota::HandleError
|
||||
MOZ_NEVER_INLINE void HandleError(const nsLiteralCString& aExpr,
|
||||
const nsLiteralCString& aSourceFile,
|
||||
MOZ_NEVER_INLINE void HandleError(const char* aExpr, const char* aSourceFile,
|
||||
int32_t aSourceLine);
|
||||
|
||||
} // namespace localstorage
|
||||
|
@ -155,11 +155,12 @@ nsDependentCSubstring GetLeafName(const nsACString& aPath) {
|
||||
return nsDependentCSubstring(start.get(), end.get());
|
||||
}
|
||||
|
||||
void LogError(const nsLiteralCString& aModule, const nsLiteralCString& aExpr,
|
||||
const nsLiteralCString& aSourceFile, int32_t aSourceLine) {
|
||||
void LogError(const nsLiteralCString& aModule, const nsACString& aExpr,
|
||||
const nsACString& aSourceFile, int32_t aSourceLine) {
|
||||
#ifdef DEBUG
|
||||
NS_DebugBreak(NS_DEBUG_WARNING, nsAutoCString(aModule + " failure"_ns).get(),
|
||||
aExpr.get(), nsAutoCString(GetLeafName(aSourceFile)).get(),
|
||||
nsPromiseFlatCString(aExpr).get(),
|
||||
nsPromiseFlatCString(GetLeafName(aSourceFile)).get(),
|
||||
aSourceLine);
|
||||
#endif
|
||||
|
||||
@ -224,9 +225,10 @@ Result<bool, nsresult> WarnIfFileIsUnknown(nsIFile& aFile,
|
||||
}
|
||||
#endif
|
||||
|
||||
void HandleError(const nsLiteralCString& aExpr,
|
||||
const nsLiteralCString& aSourceFile, int32_t aSourceLine) {
|
||||
LogError(nsLiteralCString("QuotaManager"), aExpr, aSourceFile, aSourceLine);
|
||||
void HandleError(const char* const aExpr, const char* const aSourceFile,
|
||||
const int32_t aSourceLine) {
|
||||
LogError(nsLiteralCString("QuotaManager"), nsDependentCString(aExpr),
|
||||
nsDependentCString(aSourceFile), aSourceLine);
|
||||
|
||||
// TODO: Report to telemetry
|
||||
}
|
||||
|
@ -397,12 +397,9 @@
|
||||
} while (0)
|
||||
|
||||
#ifdef DEBUG
|
||||
# define QM_HANDLE_ERROR(expr) \
|
||||
HandleError(nsLiteralCString(#expr), nsLiteralCString(__FILE__), __LINE__)
|
||||
# define QM_HANDLE_ERROR(expr) HandleError(# expr, __FILE__, __LINE__)
|
||||
#else
|
||||
# define QM_HANDLE_ERROR(expr) \
|
||||
HandleError(nsLiteralCString("Unavailable"), nsLiteralCString(__FILE__), \
|
||||
__LINE__)
|
||||
# define QM_HANDLE_ERROR(expr) HandleError("Unavailable", __FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
// QM_TRY_PROPAGATE_ERR, QM_TRY_CUSTOM_RET_VAL,
|
||||
@ -834,8 +831,8 @@ nsAutoCString GetIntCString(const int64_t aInteger);
|
||||
|
||||
nsDependentCSubstring GetLeafName(const nsACString& aPath);
|
||||
|
||||
void LogError(const nsLiteralCString& aModule, const nsLiteralCString& aExpr,
|
||||
const nsLiteralCString& aSourceFile, int32_t aSourceLine);
|
||||
void LogError(const nsLiteralCString& aModule, const nsACString& aExpr,
|
||||
const nsACString& aSourceFile, int32_t aSourceLine);
|
||||
|
||||
#ifdef DEBUG
|
||||
Result<bool, nsresult> WarnIfFileIsUnknown(nsIFile& aFile,
|
||||
@ -844,11 +841,16 @@ Result<bool, nsresult> WarnIfFileIsUnknown(nsIFile& aFile,
|
||||
#endif
|
||||
|
||||
// As this is a function that will only be called in error cases, this is marked
|
||||
// with MOZ_NEVER_INLINE to avoid bloating the code of calling functions. The
|
||||
// corresponding functions in the quota clients should have exactly the same
|
||||
// signature incl. attributes.
|
||||
MOZ_NEVER_INLINE void HandleError(const nsLiteralCString& aExpr,
|
||||
const nsLiteralCString& aSourceFile,
|
||||
// with MOZ_NEVER_INLINE to avoid bloating the code of calling functions.
|
||||
// For the same reason, the string-ish parameters are of type const char* rather
|
||||
// than any ns*String type, to minimize the code at each call site. This
|
||||
// deliberately de-optimizes runtime performance, which is uncritical during
|
||||
// error handling.
|
||||
//
|
||||
// The corresponding functions in the quota clients should have exactly the same
|
||||
// signature incl. attributes. These functions are not intended to be called
|
||||
// directly, they should only be called from the QM_* macros.
|
||||
MOZ_NEVER_INLINE void HandleError(const char* aExpr, const char* aSourceFile,
|
||||
int32_t aSourceLine);
|
||||
|
||||
} // namespace quota
|
||||
|
@ -13,10 +13,11 @@ const char* kPrefSimpleDBEnabled = "dom.simpleDB.enabled";
|
||||
|
||||
namespace simpledb {
|
||||
|
||||
void HandleError(const nsLiteralCString& aExpr,
|
||||
const nsLiteralCString& aSourceFile, int32_t aSourceLine) {
|
||||
mozilla::dom::quota::LogError(nsLiteralCString("SimpleDB"), aExpr,
|
||||
aSourceFile, aSourceLine);
|
||||
void HandleError(const char* const aExpr, const char* const aSourceFile,
|
||||
const int32_t aSourceLine) {
|
||||
mozilla::dom::quota::LogError(nsLiteralCString("SimpleDB"),
|
||||
nsDependentCString(aExpr),
|
||||
nsDependentCString(aSourceFile), aSourceLine);
|
||||
}
|
||||
|
||||
} // namespace simpledb
|
||||
|
@ -50,8 +50,7 @@ extern const char* kPrefSimpleDBEnabled;
|
||||
namespace simpledb {
|
||||
|
||||
// See comment on mozilla::dom::quota::HandleError
|
||||
MOZ_NEVER_INLINE void HandleError(const nsLiteralCString& aExpr,
|
||||
const nsLiteralCString& aSourceFile,
|
||||
MOZ_NEVER_INLINE void HandleError(const char* aExpr, const char* aSourceFile,
|
||||
int32_t aSourceLine);
|
||||
|
||||
} // namespace simpledb
|
||||
|
Loading…
x
Reference in New Issue
Block a user