Keystore 2.0: Small performance gain
When 'alias' does not start with 'keystore2_grant_id_prefix',
we'll stop looking immediately, instead of continuing to look
throughout 'alias' for further substring matches.
Test: TreeHugger
Bug: 173546268
Bug: 171305607
Bug: 175068876
Change-Id: I40057abce165b18e6bc0cb38daebef81401b5a72
diff --git a/keystore-engine/keystore2_engine.cpp b/keystore-engine/keystore2_engine.cpp
index 8d25f48..18534a1 100644
--- a/keystore-engine/keystore2_engine.cpp
+++ b/keystore-engine/keystore2_engine.cpp
@@ -357,7 +357,7 @@
// If the key_id starts with the grant id prefix, we parse the following string as numeric
// grant id. We can then use the grant domain without alias to load the designated key.
- if (alias.find(keystore2_grant_id_prefix) == 0) {
+ if (android::base::StartsWith(alias, keystore2_grant_id_prefix)) {
std::stringstream s(alias.substr(keystore2_grant_id_prefix.size()));
s >> std::hex >> reinterpret_cast<uint64_t&>(descriptor.nspace);
descriptor.domain = ks2::Domain::GRANT;