Commit 457c51e5 authored by jww@chromium.org's avatar jww@chromium.org

Cleanup a few loops into the new C++11 for-each style.

Inspired by changes in https://codereview.chromium.org/700463003/, this
CL cleans up a few loops where there was an ugly sizeof() calculation
needed. The new C++11 for-each style makes these unnecessary, thus
making the code more readable and less brittle.

R=mkwst@chromium.org

Review URL: https://codereview.chromium.org/680393005

git-svn-id: svn://svn.chromium.org/blink/trunk@184823 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f95aa553
......@@ -63,13 +63,9 @@ static String algorithmToString(HashAlgorithm algorithm)
{ HashAlgorithmSha512, "SHA-512" }
};
// See comment in parseIntegrityAttribute about why sizeof() is used
// instead of WTF_ARRAY_LENGTH.
size_t i = 0;
size_t kSupportedAlgorithmsLength = sizeof(kAlgorithmToString) / sizeof(kAlgorithmToString[0]);
for (; i < kSupportedAlgorithmsLength; i++) {
if (kAlgorithmToString[i].algorithm == algorithm)
return kAlgorithmToString[i].name;
for (const auto& algorithmToString : kAlgorithmToString) {
if (algorithmToString.algorithm == algorithm)
return algorithmToString.name;
}
ASSERT_NOT_REACHED();
......
......@@ -376,13 +376,11 @@ bool checkDigest(const String& source, uint8_t hashAlgorithmsUsed, const CSPDire
StringUTF8Adaptor normalizedSource(source, StringUTF8Adaptor::Normalize, WTF::EntitiesForUnencodables);
// See comment in CSPSourceList::parseHash about why we are using this sizeof
// calculation instead of WTF_ARRAY_LENGTH.
for (size_t i = 0; i < (sizeof(kAlgorithmMap) / sizeof(kAlgorithmMap[0])); i++) {
for (const auto& algorithmMap : kAlgorithmMap) {
DigestValue digest;
if (kAlgorithmMap[i].cspHashAlgorithm & hashAlgorithmsUsed) {
bool digestSuccess = computeDigest(kAlgorithmMap[i].algorithm, normalizedSource.data(), normalizedSource.length(), digest);
if (digestSuccess && isAllowedByAllWithHash<allowed>(policies, CSPHashValue(kAlgorithmMap[i].cspHashAlgorithm, digest)))
if (algorithmMap.cspHashAlgorithm & hashAlgorithmsUsed) {
bool digestSuccess = computeDigest(algorithmMap.algorithm, normalizedSource.data(), normalizedSource.length(), digest);
if (digestSuccess && isAllowedByAllWithHash<allowed>(policies, CSPHashValue(algorithmMap.cspHashAlgorithm, digest)))
return true;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment