Refactor VP8LColorCacheContains()

Return key/index if the query is found, and -1 otherwise.
The benefit of this is to save a hashing computation.

Change-Id: Iff056be330f5fb8204011259ac814f7677dd40fe
This commit is contained in:
hui su
2016-08-12 15:16:06 -07:00
parent 40872fb2e6
commit 1269dc7cfb
2 changed files with 12 additions and 7 deletions

View File

@ -53,10 +53,11 @@ static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc,
return (kHashMul * argb) >> cc->hash_shift_;
}
// Return the key if cc contains argb, and -1 otherwise.
static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc,
uint32_t argb) {
const uint32_t key = (kHashMul * argb) >> cc->hash_shift_;
return (cc->colors_[key] == argb);
return (cc->colors_[key] == argb) ? (int)key : -1;
}
//------------------------------------------------------------------------------