Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: src/core/SkTSearch.cpp

Issue 72603005: Guard against most unintentionally ephemeral SkAutoFoo instantiations. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: docs and REQUIRE_LOCAL_VAR Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
12 11
13 static inline const char* index_into_base(const char*const* base, int index, 12 static inline const char* index_into_base(const char*const* base, int index,
14 size_t elemSize) 13 size_t elemSize)
15 { 14 {
16 return *(const char*const*)((const char*)base + index * elemSize); 15 return *(const char*const*)((const char*)base + index * elemSize);
17 } 16 }
18 17
19 int SkStrSearch(const char*const* base, int count, const char target[], 18 int SkStrSearch(const char*const* base, int count, const char target[],
20 size_t target_len, size_t elemSize) 19 size_t target_len, size_t elemSize)
21 { 20 {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 SkAutoAsciiToLC tolc(target, len); 65 SkAutoAsciiToLC tolc(target, len);
67 66
68 return SkStrSearch(base, count, tolc.lc(), len, elemSize); 67 return SkStrSearch(base, count, tolc.lc(), len, elemSize);
69 } 68 }
70 69
71 int SkStrLCSearch(const char*const* base, int count, const char target[], 70 int SkStrLCSearch(const char*const* base, int count, const char target[],
72 size_t elemSize) 71 size_t elemSize)
73 { 72 {
74 return SkStrLCSearch(base, count, target, strlen(target), elemSize); 73 return SkStrLCSearch(base, count, target, strlen(target), elemSize);
75 } 74 }
76
77 //////////////////////////////////////////////////////////////////////////////
78
79 SkAutoAsciiToLC::SkAutoAsciiToLC(const char str[], size_t len)
80 {
81 // see if we need to compute the length
82 if ((long)len < 0) {
83 len = strlen(str);
84 }
85 fLength = len;
86
87 // assign lc to our preallocated storage if len is small enough, or allocate
88 // it on the heap
89 char* lc;
90 if (len <= STORAGE) {
91 lc = fStorage;
92 } else {
93 lc = (char*)sk_malloc_throw(len + 1);
94 }
95 fLC = lc;
96
97 // convert any asii to lower-case. we let non-ascii (utf8) chars pass
98 // through unchanged
99 for (int i = (int)(len - 1); i >= 0; --i) {
100 int c = str[i];
101 if ((c & 0x80) == 0) { // is just ascii
102 c = tolower(c);
103 }
104 lc[i] = c;
105 }
106 lc[len] = 0;
107 }
108
109 SkAutoAsciiToLC::~SkAutoAsciiToLC()
110 {
111 if (fLC != fStorage) {
112 sk_free(fLC);
113 }
114 }
OLDNEW
« src/core/SkDraw.cpp ('K') | « src/core/SkString.cpp ('k') | src/ports/SkFontHost_win.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698