-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit 5488d5d
Fixes: #10938
Keep allocated memory when rhs fits
Use case: Appending to a String with pre-allocated memory (e.g. from `reserve()`)
No need to move 0-termination char in String::move
Simplify calls to String::copy
A lot of the same checks were done before calling `copy()` which should be done in the `copy()` function itself.
String::copy() Should not copy more than given length
Fix potential out of range in String::concat
There is no prerequisite the given array has to be a 0-terminated char array.
So we should only copy the length that has been given.
The `setLen()` function will make sure the internal string is 0-terminated.
So no need to dangerously assume there will be 1 more byte to copy
Allow String::concat(const String &s) with s.buffer() == nullptr
When constructing a String object, the internal buffer is a nullptr.
However concatenating this to another String would return `false` while this is perfectly fine to do.
1 parent 6fb55a7 commit 5488d5d
1 file changed
+21
-33
lines changedLines changed: 21 additions & 33 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
226 | 226 |
| |
227 | 227 |
| |
228 | 228 |
| |
229 | - | ||
229 | + | ||
230 | 230 |
| |
231 | 231 |
| |
232 | 232 |
| |
233 | - | ||
233 | + | ||
234 | 234 |
| |
235 | 235 |
| |
236 | 236 |
| |
| |||
239 | 239 |
| |
240 | 240 |
| |
241 | 241 |
| |
242 | - | ||
242 | + | ||
243 | + | ||
244 | + | ||
245 | + | ||
246 | + | ||
243 | 247 |
| |
244 | 248 |
| |
245 | 249 |
| |
246 | - | ||
247 | - | ||
248 | - | ||
249 | - | ||
250 | - | ||
250 | + | ||
251 | + | ||
252 | + | ||
253 | + | ||
251 | 254 |
| |
252 | 255 |
| |
253 | 256 |
| |
| |||
259 | 262 |
| |
260 | 263 |
| |
261 | 264 |
| |
262 | - | ||
263 | - | ||
264 | - | ||
265 | - | ||
265 | + | ||
266 | 266 |
| |
267 | 267 |
| |
268 | 268 |
| |
269 | 269 |
| |
270 | 270 |
| |
271 | 271 |
| |
272 | 272 |
| |
273 | - | ||
274 | - | ||
275 | - | ||
276 | - | ||
277 | - | ||
278 | - | ||
273 | + | ||
279 | 274 |
| |
280 | 275 |
| |
281 | 276 |
| |
| |||
295 | 290 |
| |
296 | 291 |
| |
297 | 292 |
| |
298 | - | ||
299 | - | ||
300 | - | ||
301 | - | ||
302 | - | ||
303 | - | ||
293 | + | ||
304 | 294 |
| |
305 | 295 |
| |
306 | 296 |
| |
| |||
311 | 301 |
| |
312 | 302 |
| |
313 | 303 |
| |
314 | - | ||
315 | - | ||
316 | - | ||
317 | - | ||
318 | 304 |
| |
319 | 305 |
| |
320 | 306 |
| |
307 | + | ||
308 | + | ||
309 | + | ||
310 | + | ||
321 | 311 |
| |
322 | 312 |
| |
323 | 313 |
| |
324 | 314 |
| |
325 | 315 |
| |
326 | - | ||
327 | 316 |
| |
328 | - | ||
329 | - | ||
330 | 317 |
| |
318 | + | ||
331 | 319 |
| |
332 | 320 |
| |
333 | 321 |
| |
| |||
343 | 331 |
| |
344 | 332 |
| |
345 | 333 |
| |
346 | - | ||
334 | + | ||
347 | 335 |
| |
348 | 336 |
| |
349 | - | ||
337 | + | ||
350 | 338 |
| |
351 | 339 |
| |
352 | 340 |
| |
|
0 commit comments