Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf02b984 authored by Jeff Brown's avatar Jeff Brown Committed by Android (Google) Code Review
Browse files

Merge "Remove dead code in StringPool."

parents 4eb7fbb2 345b7eb8
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -2598,7 +2598,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)

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

        StringPool typeStrings = StringPool(false, useUTF8);
        StringPool keyStrings = StringPool(false, useUTF8);
        StringPool typeStrings(useUTF8);
        StringPool keyStrings(useUTF8);

        const size_t N = p->getOrderedTypes().size();
        for (size_t ti=0; ti<N; ti++) {
+15 −77
Original line number Diff line number Diff line
@@ -98,39 +98,24 @@ int StringPool::entry::compare(const entry& o) const {
    return 0;
}

StringPool::StringPool(bool sorted, bool utf8)
    : mSorted(sorted), mUTF8(utf8), mValues(-1), mIdents(-1)
StringPool::StringPool(bool utf8) :
        mUTF8(utf8), mValues(-1)
{
}

ssize_t StringPool::add(const String16& value, bool mergeDuplicates,
        const String8* configTypeName, const ResTable_config* config)
{
    return add(String16(), value, mergeDuplicates, configTypeName, config);
}

ssize_t StringPool::add(const String16& value, const Vector<entry_style_span>& spans,
        const String8* configTypeName, const ResTable_config* config)
{
    ssize_t res = add(String16(), value, false, configTypeName, config);
    ssize_t res = add(value, false, configTypeName, config);
    if (res >= 0) {
        addStyleSpans(res, spans);
    }
    return res;
}

ssize_t StringPool::add(const String16& ident, const String16& value,
ssize_t StringPool::add(const String16& value,
        bool mergeDuplicates, const String8* configTypeName, const ResTable_config* config)
{
    if (ident.size() > 0) {
        ssize_t idx = mIdents.valueFor(ident);
        if (idx >= 0) {
            fprintf(stderr, "ERROR: Duplicate string identifier %s\n",
                    String8(mEntries[idx].value).string());
            return UNKNOWN_ERROR;
        }
    }

    ssize_t vidx = mValues.indexOfKey(value);
    ssize_t pos = vidx >= 0 ? mValues.valueAt(vidx) : -1;
    ssize_t eidx = pos >= 0 ? mEntryArray.itemAt(pos) : -1;
@@ -181,15 +166,9 @@ ssize_t StringPool::add(const String16& ident, const String16& value,
        if (first) {
            vidx = mValues.add(value, pos);
        }
        if (!mSorted) {
        entry& ent = mEntries.editItemAt(eidx);
        ent.indices.add(pos);
    }
    }

    if (ident.size() > 0) {
        mIdents.add(ident, vidx);
    }

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

status_t StringPool::addStyleSpan(size_t idx, const entry_style_span& span)
{
    LOG_ALWAYS_FATAL_IF(mSorted, "Can't use styles with sorted string pools.");

    // Place blank entries in the span array up to this index.
    while (mEntryStyleArray.size() <= idx) {
        mEntryStyleArray.add();
@@ -234,25 +211,6 @@ status_t StringPool::addStyleSpan(size_t idx, const entry_style_span& span)
    return NO_ERROR;
}

size_t StringPool::size() const
{
    return mSorted ? mValues.size() : mEntryArray.size();
}

const StringPool::entry& StringPool::entryAt(size_t idx) const
{
    if (!mSorted) {
        return mEntries[mEntryArray[idx]];
    } else {
        return mEntries[mEntryArray[mValues.valueAt(idx)]];
    }
}

size_t StringPool::countIdentifiers() const
{
    return mIdents.size();
}

int StringPool::config_sort(const size_t* lhs, const size_t* rhs, void* state)
{
    StringPool* pool = (StringPool*)state;
@@ -263,8 +221,6 @@ int StringPool::config_sort(const size_t* lhs, const size_t* rhs, void* state)

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

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

    const size_t ENTRIES = size();
    const size_t ENTRIES = mEntryArray.size();

    // Now build the pool of unique strings.

@@ -566,9 +522,6 @@ status_t StringPool::writeStringBlock(const sp<AaptFile>& pool)
    header->header.size = htodl(pool->getSize());
    header->stringCount = htodl(ENTRIES);
    header->styleCount = htodl(STYLES);
    if (mSorted) {
        header->flags |= htodl(ResStringPool_header::SORTED_FLAG);
    }
    if (mUTF8) {
        header->flags |= htodl(ResStringPool_header::UTF8_FLAG);
    }
@@ -578,14 +531,6 @@ status_t StringPool::writeStringBlock(const sp<AaptFile>& pool)
    // Write string index array.

    uint32_t* index = (uint32_t*)(header+1);
    if (mSorted) {
        for (i=0; i<ENTRIES; i++) {
            entry& ent = const_cast<entry&>(entryAt(i));
            ent.indices.clear();
            ent.indices.add(i);
            *index++ = htodl(ent.offset);
        }
    } else {
    for (i=0; i<ENTRIES; i++) {
        entry& ent = mEntries.editItemAt(mEntryArray[i]);
        *index++ = htodl(ent.offset);
@@ -593,19 +538,12 @@ status_t StringPool::writeStringBlock(const sp<AaptFile>& pool)
                String8(ent.value).string(),
                mEntryArray[i], ent.offset));
    }
    }

    // Write style index array.

    if (mSorted) {
        for (i=0; i<STYLES; i++) {
            LOG_ALWAYS_FATAL("Shouldn't be here!");
        }
    } else {
    for (i=0; i<STYLES; i++) {
        *index++ = htodl(mEntryStyleArray[i].offset);
    }
    }

    return NO_ERROR;
}
+3 −25
Original line number Diff line number Diff line
@@ -80,16 +80,10 @@ public:
    };

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

    /**
     * Add a new string to the pool.  If mergeDuplicates is true, thenif
@@ -97,9 +91,7 @@ public:
     * otherwise, or if the value doesn't already exist, a new entry is
     * created.
     *
     * Returns the index in the entry array of the new string entry.  Note that
     * if this string pool is sorted, the returned index will not be valid
     * when the pool is finally written.
     * Returns the index in the entry array of the new string entry.
     */
    ssize_t add(const String16& value, bool mergeDuplicates = false,
            const String8* configTypeName = NULL, const ResTable_config* config = NULL);
@@ -107,24 +99,14 @@ public:
    ssize_t add(const String16& value, const Vector<entry_style_span>& spans,
            const String8* configTypeName = NULL, const ResTable_config* config = NULL);

    ssize_t add(const String16& ident, const String16& value,
                bool mergeDuplicates = false,
                const String8* configTypeName = NULL, const ResTable_config* config = NULL);

    status_t addStyleSpan(size_t idx, const String16& name,
                          uint32_t start, uint32_t end);
    status_t addStyleSpans(size_t idx, const Vector<entry_style_span>& spans);
    status_t addStyleSpan(size_t idx, const entry_style_span& span);

    size_t size() const;

    const entry& entryAt(size_t idx) const;

    size_t countIdentifiers() const;

    // Sort the contents of the string block by the configuration associated
    // with each item.  After doing this you can use mapOriginalPosToNewPos()
    // to find out the new position given the position originall returned by
    // to find out the new position given the position originally returned by
    // add().
    void sortByConfig();

@@ -159,7 +141,6 @@ public:
private:
    static int config_sort(const size_t* lhs, const size_t* rhs, void* state);

    const bool                              mSorted;
    const bool                              mUTF8;

    // The following data structures represent the actual structures
@@ -186,9 +167,6 @@ private:
    // Unique set of all the strings added to the pool, mapped to
    // the first index of mEntryArray where the value was added.
    DefaultKeyedVector<String16, ssize_t>   mValues;
    // Unique set of all (optional) identifiers of strings in the
    // pool, mapping to indices in mEntries.
    DefaultKeyedVector<String16, ssize_t>   mIdents;
    // This array maps from the original position a string was placed at
    // in mEntryArray to its new position after being sorted with sortByConfig().
    Vector<size_t>                          mOriginalPosToNewPos;
+1 −1
Original line number Diff line number Diff line
@@ -973,7 +973,7 @@ status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
status_t XMLNode::flatten(const sp<AaptFile>& dest,
        bool stripComments, bool stripRawValues) const
{
    StringPool strings = StringPool(false, mUTF8);
    StringPool strings(mUTF8);
    Vector<uint32_t> resids;
    
    // First collect just the strings for attribute names that have a