OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkTSearch.h" | 10 #include "SkTSearch.h" |
11 #include <ctype.h> | 11 #include <ctype.h> |
12 | 12 |
13 static inline const char* index_into_base(const char*const* base, int index, | 13 static inline const char* index_into_base(const char*const* base, int index, |
14 size_t elemSize) | 14 size_t elemSize) |
15 { | 15 { |
16 return *(const char*const*)((const char*)base + index * elemSize); | 16 return *(const char*const*)((const char*)base + index * elemSize); |
17 } | 17 } |
18 | 18 |
19 int SkStrSearch(const char*const* base, int count, const char target[], | 19 int SkStrSearch(const char*const* base, int count, const char target[], |
20 size_t target_len, size_t elemSize) | 20 size_t target_len, size_t elemSize) |
21 { | 21 { |
22 if (count <= 0) | 22 if (count <= 0) |
23 return ~0; | 23 return ~0; |
24 | 24 |
25 SkASSERT(base != NULL); | 25 SkASSERT(base != nullptr); |
26 | 26 |
27 int lo = 0; | 27 int lo = 0; |
28 int hi = count - 1; | 28 int hi = count - 1; |
29 | 29 |
30 while (lo < hi) | 30 while (lo < hi) |
31 { | 31 { |
32 int mid = (hi + lo) >> 1; | 32 int mid = (hi + lo) >> 1; |
33 const char* elem = index_into_base(base, mid, elemSize); | 33 const char* elem = index_into_base(base, mid, elemSize); |
34 | 34 |
35 int cmp = strncmp(elem, target, target_len); | 35 int cmp = strncmp(elem, target, target_len); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 105 } |
106 lc[len] = 0; | 106 lc[len] = 0; |
107 } | 107 } |
108 | 108 |
109 SkAutoAsciiToLC::~SkAutoAsciiToLC() | 109 SkAutoAsciiToLC::~SkAutoAsciiToLC() |
110 { | 110 { |
111 if (fLC != fStorage) { | 111 if (fLC != fStorage) { |
112 sk_free(fLC); | 112 sk_free(fLC); |
113 } | 113 } |
114 } | 114 } |
OLD | NEW |