Skip to content

Commit 345b7eb

Browse files
author
Jeff Brown
committed
Remove dead code in StringPool.
The sorted string pool option was no longer used. Neither were strings with associated identifiers. Change-Id: Ic5f6368637fbeedfda873d63f4ad0f3ea9d0d603
1 parent 8a9cfcc commit 345b7eb

File tree

4 files changed

+22
-106
lines changed

4 files changed

+22
-106
lines changed

tools/aapt/ResourceTable.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,7 +2598,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
25982598

25992599
// Iterate through all data, collecting all values (strings,
26002600
// references, etc).
2601-
StringPool valueStrings = StringPool(false, useUTF8);
2601+
StringPool valueStrings(useUTF8);
26022602
Vector<sp<Entry> > allEntries;
26032603
for (pi=0; pi<N; pi++) {
26042604
sp<Package> p = mOrderedPackages.itemAt(pi);
@@ -2607,8 +2607,8 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
26072607
continue;
26082608
}
26092609

2610-
StringPool typeStrings = StringPool(false, useUTF8);
2611-
StringPool keyStrings = StringPool(false, useUTF8);
2610+
StringPool typeStrings(useUTF8);
2611+
StringPool keyStrings(useUTF8);
26122612

26132613
const size_t N = p->getOrderedTypes().size();
26142614
for (size_t ti=0; ti<N; ti++) {

tools/aapt/StringPool.cpp

Lines changed: 15 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -98,39 +98,24 @@ int StringPool::entry::compare(const entry& o) const {
9898
return 0;
9999
}
100100

101-
StringPool::StringPool(bool sorted, bool utf8)
102-
: mSorted(sorted), mUTF8(utf8), mValues(-1), mIdents(-1)
101+
StringPool::StringPool(bool utf8) :
102+
mUTF8(utf8), mValues(-1)
103103
{
104104
}
105105

106-
ssize_t StringPool::add(const String16& value, bool mergeDuplicates,
107-
const String8* configTypeName, const ResTable_config* config)
108-
{
109-
return add(String16(), value, mergeDuplicates, configTypeName, config);
110-
}
111-
112106
ssize_t StringPool::add(const String16& value, const Vector<entry_style_span>& spans,
113107
const String8* configTypeName, const ResTable_config* config)
114108
{
115-
ssize_t res = add(String16(), value, false, configTypeName, config);
109+
ssize_t res = add(value, false, configTypeName, config);
116110
if (res >= 0) {
117111
addStyleSpans(res, spans);
118112
}
119113
return res;
120114
}
121115

122-
ssize_t StringPool::add(const String16& ident, const String16& value,
116+
ssize_t StringPool::add(const String16& value,
123117
bool mergeDuplicates, const String8* configTypeName, const ResTable_config* config)
124118
{
125-
if (ident.size() > 0) {
126-
ssize_t idx = mIdents.valueFor(ident);
127-
if (idx >= 0) {
128-
fprintf(stderr, "ERROR: Duplicate string identifier %s\n",
129-
String8(mEntries[idx].value).string());
130-
return UNKNOWN_ERROR;
131-
}
132-
}
133-
134119
ssize_t vidx = mValues.indexOfKey(value);
135120
ssize_t pos = vidx >= 0 ? mValues.valueAt(vidx) : -1;
136121
ssize_t eidx = pos >= 0 ? mEntryArray.itemAt(pos) : -1;
@@ -181,14 +166,8 @@ ssize_t StringPool::add(const String16& ident, const String16& value,
181166
if (first) {
182167
vidx = mValues.add(value, pos);
183168
}
184-
if (!mSorted) {
185-
entry& ent = mEntries.editItemAt(eidx);
186-
ent.indices.add(pos);
187-
}
188-
}
189-
190-
if (ident.size() > 0) {
191-
mIdents.add(ident, vidx);
169+
entry& ent = mEntries.editItemAt(eidx);
170+
ent.indices.add(pos);
192171
}
193172

194173
NOISY(printf("Adding string %s to pool: pos=%d eidx=%d vidx=%d\n",
@@ -221,8 +200,6 @@ status_t StringPool::addStyleSpans(size_t idx, const Vector<entry_style_span>& s
221200

222201
status_t StringPool::addStyleSpan(size_t idx, const entry_style_span& span)
223202
{
224-
LOG_ALWAYS_FATAL_IF(mSorted, "Can't use styles with sorted string pools.");
225-
226203
// Place blank entries in the span array up to this index.
227204
while (mEntryStyleArray.size() <= idx) {
228205
mEntryStyleArray.add();
@@ -234,25 +211,6 @@ status_t StringPool::addStyleSpan(size_t idx, const entry_style_span& span)
234211
return NO_ERROR;
235212
}
236213

237-
size_t StringPool::size() const
238-
{
239-
return mSorted ? mValues.size() : mEntryArray.size();
240-
}
241-
242-
const StringPool::entry& StringPool::entryAt(size_t idx) const
243-
{
244-
if (!mSorted) {
245-
return mEntries[mEntryArray[idx]];
246-
} else {
247-
return mEntries[mEntryArray[mValues.valueAt(idx)]];
248-
}
249-
}
250-
251-
size_t StringPool::countIdentifiers() const
252-
{
253-
return mIdents.size();
254-
}
255-
256214
int StringPool::config_sort(const size_t* lhs, const size_t* rhs, void* state)
257215
{
258216
StringPool* pool = (StringPool*)state;
@@ -263,8 +221,6 @@ int StringPool::config_sort(const size_t* lhs, const size_t* rhs, void* state)
263221

264222
void StringPool::sortByConfig()
265223
{
266-
LOG_ALWAYS_FATAL_IF(mSorted, "Can't sort string pool containing identifiers.");
267-
LOG_ALWAYS_FATAL_IF(mIdents.size() > 0, "Can't sort string pool containing identifiers.");
268224
LOG_ALWAYS_FATAL_IF(mOriginalPosToNewPos.size() > 0, "Can't sort string pool after already sorted.");
269225

270226
const size_t N = mEntryArray.size();
@@ -432,7 +388,7 @@ status_t StringPool::writeStringBlock(const sp<AaptFile>& pool)
432388
}
433389
}
434390

435-
const size_t ENTRIES = size();
391+
const size_t ENTRIES = mEntryArray.size();
436392

437393
// Now build the pool of unique strings.
438394

@@ -566,9 +522,6 @@ status_t StringPool::writeStringBlock(const sp<AaptFile>& pool)
566522
header->header.size = htodl(pool->getSize());
567523
header->stringCount = htodl(ENTRIES);
568524
header->styleCount = htodl(STYLES);
569-
if (mSorted) {
570-
header->flags |= htodl(ResStringPool_header::SORTED_FLAG);
571-
}
572525
if (mUTF8) {
573526
header->flags |= htodl(ResStringPool_header::UTF8_FLAG);
574527
}
@@ -578,33 +531,18 @@ status_t StringPool::writeStringBlock(const sp<AaptFile>& pool)
578531
// Write string index array.
579532

580533
uint32_t* index = (uint32_t*)(header+1);
581-
if (mSorted) {
582-
for (i=0; i<ENTRIES; i++) {
583-
entry& ent = const_cast<entry&>(entryAt(i));
584-
ent.indices.clear();
585-
ent.indices.add(i);
586-
*index++ = htodl(ent.offset);
587-
}
588-
} else {
589-
for (i=0; i<ENTRIES; i++) {
590-
entry& ent = mEntries.editItemAt(mEntryArray[i]);
591-
*index++ = htodl(ent.offset);
592-
NOISY(printf("Writing entry #%d: \"%s\" ent=%d off=%d\n", i,
593-
String8(ent.value).string(),
594-
mEntryArray[i], ent.offset));
595-
}
534+
for (i=0; i<ENTRIES; i++) {
535+
entry& ent = mEntries.editItemAt(mEntryArray[i]);
536+
*index++ = htodl(ent.offset);
537+
NOISY(printf("Writing entry #%d: \"%s\" ent=%d off=%d\n", i,
538+
String8(ent.value).string(),
539+
mEntryArray[i], ent.offset));
596540
}
597541

598542
// Write style index array.
599543

600-
if (mSorted) {
601-
for (i=0; i<STYLES; i++) {
602-
LOG_ALWAYS_FATAL("Shouldn't be here!");
603-
}
604-
} else {
605-
for (i=0; i<STYLES; i++) {
606-
*index++ = htodl(mEntryStyleArray[i].offset);
607-
}
544+
for (i=0; i<STYLES; i++) {
545+
*index++ = htodl(mEntryStyleArray[i].offset);
608546
}
609547

610548
return NO_ERROR;

tools/aapt/StringPool.h

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,51 +80,33 @@ class StringPool
8080
};
8181

8282
/**
83-
* If 'sorted' is true, then the final strings in the resource data
84-
* structure will be generated in sorted order. This allow for fast
85-
* lookup with ResStringPool::indexOfString() (O(log n)), at the expense
86-
* of support for styled string entries (which requires the same string
87-
* be included multiple times in the pool).
88-
*
8983
* If 'utf8' is true, strings will be encoded with UTF-8 instead of
9084
* left in Java's native UTF-16.
9185
*/
92-
explicit StringPool(bool sorted = false, bool utf8 = false);
86+
explicit StringPool(bool utf8 = false);
9387

9488
/**
9589
* Add a new string to the pool. If mergeDuplicates is true, thenif
9690
* the string already exists the existing entry for it will be used;
9791
* otherwise, or if the value doesn't already exist, a new entry is
9892
* created.
9993
*
100-
* Returns the index in the entry array of the new string entry. Note that
101-
* if this string pool is sorted, the returned index will not be valid
102-
* when the pool is finally written.
94+
* Returns the index in the entry array of the new string entry.
10395
*/
10496
ssize_t add(const String16& value, bool mergeDuplicates = false,
10597
const String8* configTypeName = NULL, const ResTable_config* config = NULL);
10698

10799
ssize_t add(const String16& value, const Vector<entry_style_span>& spans,
108100
const String8* configTypeName = NULL, const ResTable_config* config = NULL);
109101

110-
ssize_t add(const String16& ident, const String16& value,
111-
bool mergeDuplicates = false,
112-
const String8* configTypeName = NULL, const ResTable_config* config = NULL);
113-
114102
status_t addStyleSpan(size_t idx, const String16& name,
115103
uint32_t start, uint32_t end);
116104
status_t addStyleSpans(size_t idx, const Vector<entry_style_span>& spans);
117105
status_t addStyleSpan(size_t idx, const entry_style_span& span);
118106

119-
size_t size() const;
120-
121-
const entry& entryAt(size_t idx) const;
122-
123-
size_t countIdentifiers() const;
124-
125107
// Sort the contents of the string block by the configuration associated
126108
// with each item. After doing this you can use mapOriginalPosToNewPos()
127-
// to find out the new position given the position originall returned by
109+
// to find out the new position given the position originally returned by
128110
// add().
129111
void sortByConfig();
130112

@@ -159,7 +141,6 @@ class StringPool
159141
private:
160142
static int config_sort(const size_t* lhs, const size_t* rhs, void* state);
161143

162-
const bool mSorted;
163144
const bool mUTF8;
164145

165146
// The following data structures represent the actual structures
@@ -186,9 +167,6 @@ class StringPool
186167
// Unique set of all the strings added to the pool, mapped to
187168
// the first index of mEntryArray where the value was added.
188169
DefaultKeyedVector<String16, ssize_t> mValues;
189-
// Unique set of all (optional) identifiers of strings in the
190-
// pool, mapping to indices in mEntries.
191-
DefaultKeyedVector<String16, ssize_t> mIdents;
192170
// This array maps from the original position a string was placed at
193171
// in mEntryArray to its new position after being sorted with sortByConfig().
194172
Vector<size_t> mOriginalPosToNewPos;

tools/aapt/XMLNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
973973
status_t XMLNode::flatten(const sp<AaptFile>& dest,
974974
bool stripComments, bool stripRawValues) const
975975
{
976-
StringPool strings = StringPool(false, mUTF8);
976+
StringPool strings(mUTF8);
977977
Vector<uint32_t> resids;
978978

979979
// First collect just the strings for attribute names that have a

0 commit comments

Comments
 (0)