@@ -131,10 +131,11 @@ fn initcap<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
131
131
string_array. value_data ( ) . len ( ) ,
132
132
) ;
133
133
134
+ let mut container = String :: new ( ) ;
134
135
string_array. iter ( ) . for_each ( |str| match str {
135
136
Some ( s) => {
136
- let initcap_str = initcap_string ( s) ;
137
- builder. append_value ( initcap_str ) ;
137
+ initcap_string ( s, & mut container ) ;
138
+ builder. append_value ( & container ) ;
138
139
}
139
140
None => builder. append_null ( ) ,
140
141
} ) ;
@@ -147,42 +148,41 @@ fn initcap_utf8view(args: &[ArrayRef]) -> Result<ArrayRef> {
147
148
148
149
let mut builder = StringViewBuilder :: with_capacity ( string_view_array. len ( ) ) ;
149
150
151
+ let mut container = String :: new ( ) ;
150
152
string_view_array. iter ( ) . for_each ( |str| match str {
151
153
Some ( s) => {
152
- let initcap_str = initcap_string ( s) ;
153
- builder. append_value ( initcap_str ) ;
154
+ initcap_string ( s, & mut container ) ;
155
+ builder. append_value ( & container ) ;
154
156
}
155
157
None => builder. append_null ( ) ,
156
158
} ) ;
157
159
158
160
Ok ( Arc :: new ( builder. finish ( ) ) as ArrayRef )
159
161
}
160
162
161
- fn initcap_string ( input : & str ) -> String {
162
- let mut result = String :: with_capacity ( input . len ( ) ) ;
163
+ fn initcap_string ( input : & str , container : & mut String ) {
164
+ container . clear ( ) ;
163
165
let mut prev_is_alphanumeric = false ;
164
166
165
167
if input. is_ascii ( ) {
166
168
for c in input. chars ( ) {
167
169
if prev_is_alphanumeric {
168
- result . push ( c. to_ascii_lowercase ( ) ) ;
170
+ container . push ( c. to_ascii_lowercase ( ) ) ;
169
171
} else {
170
- result . push ( c. to_ascii_uppercase ( ) ) ;
172
+ container . push ( c. to_ascii_uppercase ( ) ) ;
171
173
} ;
172
174
prev_is_alphanumeric = c. is_ascii_alphanumeric ( ) ;
173
175
}
174
176
} else {
175
177
for c in input. chars ( ) {
176
178
if prev_is_alphanumeric {
177
- result . extend ( c. to_lowercase ( ) ) ;
179
+ container . extend ( c. to_lowercase ( ) ) ;
178
180
} else {
179
- result . extend ( c. to_uppercase ( ) ) ;
181
+ container . extend ( c. to_uppercase ( ) ) ;
180
182
}
181
183
prev_is_alphanumeric = c. is_alphanumeric ( ) ;
182
184
}
183
185
}
184
-
185
- result
186
186
}
187
187
188
188
#[ cfg( test) ]
0 commit comments