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 #ifndef SkTSearch_DEFINED | 10 #ifndef SkTSearch_DEFINED |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 if (count <= 0) { | 42 if (count <= 0) { |
43 return ~0; | 43 return ~0; |
44 } | 44 } |
45 | 45 |
46 SkASSERT(base != NULL); // base may be NULL if count is zero | 46 SkASSERT(base != NULL); // base may be NULL if count is zero |
47 | 47 |
48 int lo = 0; | 48 int lo = 0; |
49 int hi = count - 1; | 49 int hi = count - 1; |
50 | 50 |
51 while (lo < hi) { | 51 while (lo < hi) { |
52 int mid = (hi + lo) >> 1; | 52 int mid = lo + ((hi - lo) >> 1); |
53 const T* elem = (const T*)((const char*)base + mid * elemSize); | 53 const T* elem = (const T*)((const char*)base + mid * elemSize); |
54 | 54 |
55 if (less(*elem, key)) | 55 if (less(*elem, key)) |
56 lo = mid + 1; | 56 lo = mid + 1; |
57 else | 57 else |
58 hi = mid; | 58 hi = mid; |
59 } | 59 } |
60 | 60 |
61 const T* elem = (const T*)((const char*)base + hi * elemSize); | 61 const T* elem = (const T*)((const char*)base + hi * elemSize); |
62 if (less(*elem, key)) { | 62 if (less(*elem, key)) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 enum { | 137 enum { |
138 STORAGE = 64 | 138 STORAGE = 64 |
139 }; | 139 }; |
140 char fStorage[STORAGE+1]; | 140 char fStorage[STORAGE+1]; |
141 }; | 141 }; |
142 | 142 |
143 // Helper when calling qsort with a compare proc that has typed its arguments | 143 // Helper when calling qsort with a compare proc that has typed its arguments |
144 #define SkCastForQSort(compare) reinterpret_cast<int (*)(const void*, const void
*)>(compare) | 144 #define SkCastForQSort(compare) reinterpret_cast<int (*)(const void*, const void
*)>(compare) |
145 | 145 |
146 #endif | 146 #endif |
OLD | NEW |