Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2006 The Android Open Source Project |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | #include "SkMemberInfo.h" |
michael@0 | 11 | |
michael@0 | 12 | #if SK_USE_CONDENSED_INFO == 1 |
michael@0 | 13 | |
michael@0 | 14 | // SkCondensed.cpp is auto-generated |
michael@0 | 15 | // To generate it, execute SkDisplayType::BuildCondensedInfo() |
michael@0 | 16 | #ifdef SK_DEBUG |
michael@0 | 17 | #include "SkCondensedDebug.cpp" |
michael@0 | 18 | #else |
michael@0 | 19 | #include "SkCondensedRelease.cpp" |
michael@0 | 20 | #endif |
michael@0 | 21 | |
michael@0 | 22 | static int _searchByName(const unsigned char* lengths, int count, const char* strings, const char target[]) { |
michael@0 | 23 | int lo = 0; |
michael@0 | 24 | int hi = count - 1; |
michael@0 | 25 | while (lo < hi) { |
michael@0 | 26 | int mid = (hi + lo) >> 1; |
michael@0 | 27 | if (strcmp(&strings[lengths[mid << 2]], target) < 0) |
michael@0 | 28 | lo = mid + 1; |
michael@0 | 29 | else |
michael@0 | 30 | hi = mid; |
michael@0 | 31 | } |
michael@0 | 32 | if (strcmp(&strings[lengths[hi << 2]], target) != 0) |
michael@0 | 33 | return -1; |
michael@0 | 34 | return hi; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | static int _searchByType(SkDisplayTypes type) { |
michael@0 | 38 | unsigned char match = (unsigned char) type; |
michael@0 | 39 | int lo = 0; |
michael@0 | 40 | int hi = kTypeIDs - 1; |
michael@0 | 41 | while (lo < hi) { |
michael@0 | 42 | int mid = (hi + lo) >> 1; |
michael@0 | 43 | if (gTypeIDs[mid] < match) |
michael@0 | 44 | lo = mid + 1; |
michael@0 | 45 | else |
michael@0 | 46 | hi = mid; |
michael@0 | 47 | } |
michael@0 | 48 | if (gTypeIDs[hi] != type) |
michael@0 | 49 | return -1; |
michael@0 | 50 | return hi; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | const SkMemberInfo* SkDisplayType::GetMembers(SkAnimateMaker* , SkDisplayTypes type, int* infoCountPtr) { |
michael@0 | 54 | int lookup = _searchByType(type); |
michael@0 | 55 | if (lookup < 0) |
michael@0 | 56 | return NULL; |
michael@0 | 57 | if (infoCountPtr) |
michael@0 | 58 | *infoCountPtr = gInfoCounts[lookup]; |
michael@0 | 59 | return gInfoTables[lookup]; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | // !!! replace with inline |
michael@0 | 63 | const SkMemberInfo* SkDisplayType::GetMember(SkAnimateMaker* , SkDisplayTypes type, const char** matchPtr ) { |
michael@0 | 64 | const SkMemberInfo* info = SkMemberInfo::Find(type, matchPtr); |
michael@0 | 65 | SkASSERT(info); |
michael@0 | 66 | return info; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | static const SkMemberInfo* _lookup(int lookup, const char** matchPtr) { |
michael@0 | 70 | int count = gInfoCounts[lookup]; |
michael@0 | 71 | const SkMemberInfo* info = gInfoTables[lookup]; |
michael@0 | 72 | if (info->fType == SkType_BaseClassInfo) { |
michael@0 | 73 | int baseTypeLookup = info->fOffset; |
michael@0 | 74 | const SkMemberInfo* result = _lookup(baseTypeLookup, matchPtr); |
michael@0 | 75 | if (result != NULL) |
michael@0 | 76 | return result; |
michael@0 | 77 | if (--count == 0) |
michael@0 | 78 | return NULL; |
michael@0 | 79 | info++; |
michael@0 | 80 | } |
michael@0 | 81 | SkASSERT(info->fType != SkType_BaseClassInfo); |
michael@0 | 82 | const char* match = *matchPtr; |
michael@0 | 83 | const char* strings = gInfoNames[lookup]; |
michael@0 | 84 | int index = _searchByName(&info->fName, count, strings, match); |
michael@0 | 85 | if (index < 0) |
michael@0 | 86 | return NULL; |
michael@0 | 87 | return &info[index]; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | const SkMemberInfo* SkMemberInfo::Find(SkDisplayTypes type, int* index) { |
michael@0 | 91 | int count = gInfoCounts[lookup]; |
michael@0 | 92 | const SkMemberInfo* info = gInfoTables[lookup]; |
michael@0 | 93 | if (info->fType == SkType_BaseClassInfo) { |
michael@0 | 94 | int baseTypeLookup = info->fOffset; |
michael@0 | 95 | const SkMemberInfo* result = Find(baseTypeLookup, index); |
michael@0 | 96 | if (result != NULL) |
michael@0 | 97 | return result; |
michael@0 | 98 | if (--count == 0) |
michael@0 | 99 | return NULL; |
michael@0 | 100 | info++; |
michael@0 | 101 | } |
michael@0 | 102 | SkASSERT(info->fType != SkType_BaseClassInfo); |
michael@0 | 103 | if (*index >= count) { |
michael@0 | 104 | *index -= count; |
michael@0 | 105 | return NULL; |
michael@0 | 106 | } |
michael@0 | 107 | return &info[index]; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | const SkMemberInfo* SkMemberInfo::Find(SkDisplayTypes type, const char** matchPtr) { |
michael@0 | 111 | int lookup = _searchByType(type); |
michael@0 | 112 | SkASSERT(lookup >= 0); |
michael@0 | 113 | return _lookup(lookup, matchPtr); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | const SkMemberInfo* SkMemberInfo::getInherited() const { |
michael@0 | 117 | int baseTypeLookup = fOffset; |
michael@0 | 118 | return gInfoTables[baseTypeLookup]; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | #endif |