Merge "androidfw: use a vector instead of manually managing memory" am: 972a78726b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1555550 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I498376352452606cdd8ac7d28817ece60002cec4
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <android-base/macros.h>
|
#include <android-base/macros.h>
|
||||||
#include <androidfw/ByteBucketArray.h>
|
#include <androidfw/ByteBucketArray.h>
|
||||||
@@ -1029,7 +1030,7 @@ base::expected<size_t, NullOrIOError> ResStringPool::indexOfString(const char16_
|
|||||||
// But we don't want to hit the cache, so instead we will have a
|
// But we don't want to hit the cache, so instead we will have a
|
||||||
// local temporary allocation for the conversions.
|
// local temporary allocation for the conversions.
|
||||||
size_t convBufferLen = strLen + 4;
|
size_t convBufferLen = strLen + 4;
|
||||||
char16_t* convBuffer = (char16_t*)calloc(convBufferLen, sizeof(char16_t));
|
std::vector<char16_t> convBuffer(convBufferLen);
|
||||||
ssize_t l = 0;
|
ssize_t l = 0;
|
||||||
ssize_t h = mHeader->stringCount-1;
|
ssize_t h = mHeader->stringCount-1;
|
||||||
|
|
||||||
@@ -1043,8 +1044,8 @@ base::expected<size_t, NullOrIOError> ResStringPool::indexOfString(const char16_
|
|||||||
}
|
}
|
||||||
if (s.has_value()) {
|
if (s.has_value()) {
|
||||||
char16_t* end = utf8_to_utf16(reinterpret_cast<const uint8_t*>(s->data()),
|
char16_t* end = utf8_to_utf16(reinterpret_cast<const uint8_t*>(s->data()),
|
||||||
s->size(), convBuffer, convBufferLen);
|
s->size(), convBuffer.data(), convBufferLen);
|
||||||
c = strzcmp16(convBuffer, end-convBuffer, str, strLen);
|
c = strzcmp16(convBuffer.data(), end-convBuffer.data(), str, strLen);
|
||||||
}
|
}
|
||||||
if (kDebugStringPoolNoisy) {
|
if (kDebugStringPoolNoisy) {
|
||||||
ALOGI("Looking at %s, cmp=%d, l/mid/h=%d/%d/%d\n",
|
ALOGI("Looking at %s, cmp=%d, l/mid/h=%d/%d/%d\n",
|
||||||
@@ -1054,7 +1055,6 @@ base::expected<size_t, NullOrIOError> ResStringPool::indexOfString(const char16_
|
|||||||
if (kDebugStringPoolNoisy) {
|
if (kDebugStringPoolNoisy) {
|
||||||
ALOGI("MATCH!");
|
ALOGI("MATCH!");
|
||||||
}
|
}
|
||||||
free(convBuffer);
|
|
||||||
return mid;
|
return mid;
|
||||||
} else if (c < 0) {
|
} else if (c < 0) {
|
||||||
l = mid + 1;
|
l = mid + 1;
|
||||||
@@ -1062,7 +1062,6 @@ base::expected<size_t, NullOrIOError> ResStringPool::indexOfString(const char16_
|
|||||||
h = mid - 1;
|
h = mid - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(convBuffer);
|
|
||||||
} else {
|
} else {
|
||||||
// It is unusual to get the ID from an unsorted string block...
|
// It is unusual to get the ID from an unsorted string block...
|
||||||
// most often this happens because we want to get IDs for style
|
// most often this happens because we want to get IDs for style
|
||||||
|
|||||||
Reference in New Issue
Block a user