| Index: include/core/SkTDict.h
|
| diff --git a/include/core/SkTDict.h b/include/core/SkTDict.h
|
| index 49d07d4614df2e515bab82f83954a54dcf8ac837..106cace2f268090ff3f104d4dccc9795536416cc 100644
|
| --- a/include/core/SkTDict.h
|
| +++ b/include/core/SkTDict.h
|
| @@ -1,4 +1,3 @@
|
| -
|
| /*
|
| * Copyright 2006 The Android Open Source Project
|
| *
|
| @@ -6,7 +5,6 @@
|
| * found in the LICENSE file.
|
| */
|
|
|
| -
|
| #ifndef SkTDict_DEFINED
|
| #define SkTDict_DEFINED
|
|
|
| @@ -18,32 +16,26 @@ template <typename T> class SkTDict : SkNoncopyable {
|
| public:
|
| SkTDict(size_t minStringAlloc) : fStrings(minStringAlloc) {}
|
|
|
| - void reset()
|
| - {
|
| + void reset() {
|
| fArray.reset();
|
| fStrings.reset();
|
| }
|
|
|
| int count() const { return fArray.count(); }
|
|
|
| - bool set(const char name[], const T& value)
|
| - {
|
| + bool set(const char name[], const T& value) {
|
| return set(name, strlen(name), value);
|
| }
|
|
|
| - bool set(const char name[], size_t len, const T& value)
|
| - {
|
| + bool set(const char name[], size_t len, const T& value) {
|
| SkASSERT(name);
|
|
|
| int index = this->find_index(name, len);
|
|
|
| - if (index >= 0)
|
| - {
|
| + if (index >= 0) {
|
| fArray[index].fValue = value;
|
| return false;
|
| - }
|
| - else
|
| - {
|
| + } else {
|
| Pair* pair = fArray.insert(~index);
|
| char* copy = (char*)fStrings.alloc(len + 1, SkChunkAlloc::kThrow_AllocFailType);
|
| memcpy(copy, name, len);
|
| @@ -54,40 +46,36 @@ public:
|
| }
|
| }
|
|
|
| - bool find(const char name[]) const
|
| - {
|
| + bool find(const char name[]) const {
|
| return this->find_index(name) >= 0;
|
| }
|
|
|
| - bool find(const char name[], size_t len) const
|
| - {
|
| + bool find(const char name[], size_t len) const {
|
| return this->find_index(name, len) >= 0;
|
| }
|
|
|
| - bool find(const char name[], T* value) const
|
| - {
|
| + bool find(const char name[], T* value) const {
|
| return find(name, strlen(name), value);
|
| }
|
|
|
| - bool find(const char name[], size_t len, T* value) const
|
| - {
|
| + bool find(const char name[], size_t len, T* value) const {
|
| int index = this->find_index(name, len);
|
|
|
| - if (index >= 0)
|
| - {
|
| - if (value)
|
| + if (index >= 0) {
|
| + if (value) {
|
| *value = fArray[index].fValue;
|
| + }
|
| return true;
|
| }
|
| return false;
|
| }
|
|
|
| - bool findKey(T& value, const char** name) const
|
| - {
|
| + bool findKey(T& value, const char** name) const {
|
| const Pair* end = fArray.end();
|
| for (const Pair* pair = fArray.begin(); pair < end; pair++) {
|
| - if (pair->fValue != value)
|
| + if (pair->fValue != value) {
|
| continue;
|
| + }
|
| *name = pair->fName;
|
| return true;
|
| }
|
| @@ -99,12 +87,11 @@ public:
|
| const char* fName;
|
| T fValue;
|
|
|
| - friend int operator<(const Pair& a, const Pair& b)
|
| - {
|
| + friend int operator<(const Pair& a, const Pair& b) {
|
| return strcmp(a.fName, b.fName);
|
| }
|
| - friend int operator!=(const Pair& a, const Pair& b)
|
| - {
|
| +
|
| + friend int operator!=(const Pair& a, const Pair& b) {
|
| return strcmp(a.fName, b.fName);
|
| }
|
| };
|
| @@ -113,19 +100,18 @@ public:
|
| public:
|
| class Iter {
|
| public:
|
| - Iter(const SkTDict<T>& dict)
|
| - {
|
| + Iter(const SkTDict<T>& dict) {
|
| fIter = dict.fArray.begin();
|
| fStop = dict.fArray.end();
|
| }
|
| - const char* next(T* value)
|
| - {
|
| +
|
| + const char* next(T* value) {
|
| const char* name = NULL;
|
| - if (fIter < fStop)
|
| - {
|
| + if (fIter < fStop) {
|
| name = fIter->fName;
|
| - if (value)
|
| + if (value) {
|
| *value = fIter->fValue;
|
| + }
|
| fIter += 1;
|
| }
|
| return name;
|
| @@ -139,20 +125,19 @@ private:
|
| SkTDArray<Pair> fArray;
|
| SkChunkAlloc fStrings;
|
|
|
| - int find_index(const char name[]) const
|
| - {
|
| + int find_index(const char name[]) const {
|
| return find_index(name, strlen(name));
|
| }
|
|
|
| - int find_index(const char name[], size_t len) const
|
| - {
|
| + int find_index(const char name[], size_t len) const {
|
| SkASSERT(name);
|
|
|
| int count = fArray.count();
|
| int index = ~0;
|
|
|
| - if (count)
|
| + if (count) {
|
| index = SkStrSearch(&fArray.begin()->fName, count, name, len, sizeof(Pair));
|
| + }
|
| return index;
|
| }
|
| friend class Iter;
|
|
|