Skip to content

Commit

Permalink
Bug 1666219 - Introduce QM_TRY_INSPECT to avoid unwrapping Result obj…
Browse files Browse the repository at this point in the history
…ects where not necessary. r=dom-workers-and-storage-reviewers,janv

Differential Revision: https://phabricator.services.mozilla.com/D90843
  • Loading branch information
sigiesec committed Sep 29, 2020
1 parent a17cd83 commit fcd3fbc
Show file tree
Hide file tree
Showing 13 changed files with 590 additions and 526 deletions.
10 changes: 6 additions & 4 deletions dom/cache/CacheCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
# define CACHE_DEBUG_TRY(...)
#endif

// Cache equivalents of QM_TRY_VAR and QM_DEBUG_TRY_VAR.
#define CACHE_TRY_VAR_GLUE(...) \
QM_TRY_VAR_META(mozilla::dom::cache, MOZ_UNIQUE_VAR(tryResult), ##__VA_ARGS__)
#define CACHE_TRY_VAR(...) CACHE_TRY_VAR_GLUE(__VA_ARGS__)
// Cache equivalents of QM_TRY_VAR, QM_TRY_INSPECT and QM_DEBUG_TRY_VAR.
#define CACHE_TRY_VAR_GLUE(accessFunction, ...) \
QM_TRY_VAR_META(mozilla::dom::cache, MOZ_UNIQUE_VAR(tryResult), \
accessFunction, ##__VA_ARGS__)
#define CACHE_TRY_VAR(...) CACHE_TRY_VAR_GLUE(unwrap, __VA_ARGS__)
#define CACHE_TRY_INSPECT(...) CACHE_TRY_VAR_GLUE(inspect, __VA_ARGS__)

#ifdef DEBUG
# define CACHE_DEBUG_TRY_VAR(...) CACHE_TRY_VAR(__VA_ARGS__)
Expand Down
18 changes: 9 additions & 9 deletions dom/cache/DBSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,8 +1243,8 @@ Result<nsTArray<EntryId>, nsresult> QueryCache(mozIStorageConnection& aConn,
return Err(rv);
}

CACHE_TRY_VAR(const auto urlWithoutQueryHash,
HashCString(*crypto, aRequest.urlWithoutQuery()));
CACHE_TRY_INSPECT(const auto& urlWithoutQueryHash,
HashCString(*crypto, aRequest.urlWithoutQuery()));

rv = state->BindUTF8StringAsBlobByName("url_no_query_hash"_ns,
urlWithoutQueryHash);
Expand All @@ -1253,8 +1253,8 @@ Result<nsTArray<EntryId>, nsresult> QueryCache(mozIStorageConnection& aConn,
}

if (!aParams.ignoreSearch()) {
CACHE_TRY_VAR(const auto urlQueryHash,
HashCString(*crypto, aRequest.urlQuery()));
CACHE_TRY_INSPECT(const auto& urlQueryHash,
HashCString(*crypto, aRequest.urlQuery()));

rv = state->BindUTF8StringAsBlobByName("url_query_hash"_ns, urlQueryHash);
if (NS_WARN_IF(NS_FAILED(rv))) {
Expand Down Expand Up @@ -1607,7 +1607,7 @@ Result<int32_t, nsresult> InsertSecurityInfo(mozIStorageConnection& aConn,
// the full blob would be quite expensive. Instead, we index a small
// hash value. Calculate this hash as the first 8 bytes of the SHA1 of
// the full data.
CACHE_TRY_VAR(const auto hash, HashCString(aCrypto, aData));
CACHE_TRY_INSPECT(const auto& hash, HashCString(aCrypto, aData));

// Next, search for an existing entry for this blob by comparing the hash
// value first and then the full data. SQLite is smart enough to use
Expand Down Expand Up @@ -1919,8 +1919,8 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId,
return rv;
}

CACHE_TRY_VAR(const auto urlWithoutQueryHash,
HashCString(*crypto, aRequest.urlWithoutQuery()));
CACHE_TRY_INSPECT(const auto& urlWithoutQueryHash,
HashCString(*crypto, aRequest.urlWithoutQuery()));

rv = state->BindUTF8StringAsBlobByName("request_url_no_query_hash"_ns,
urlWithoutQueryHash);
Expand All @@ -1933,8 +1933,8 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId,
return rv;
}

CACHE_TRY_VAR(const auto urlQueryHash,
HashCString(*crypto, aRequest.urlQuery()));
CACHE_TRY_INSPECT(const auto& urlQueryHash,
HashCString(*crypto, aRequest.urlQuery()));

rv = state->BindUTF8StringAsBlobByName("request_url_query_hash"_ns,
urlQueryHash);
Expand Down
Loading

0 comments on commit fcd3fbc

Please sign in to comment.