MCPcopy Create free account
hub / github.com/SmingHub/Sming / move

Method move

Sming/Wiring/WString.cpp:266–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

264}
265
266void String::move(String& rhs)
267{
268 if(rhs.isNull()) {
269 invalidate();
270 return;
271 }
272
273 auto rhs_len = rhs.length();
274 if(rhs.sso.set) {
275 // Switch to SSO if required (note: we don't rely on this succeeding)
276 (void)reserve(rhs_len);
277 }
278
279 // If we have more capacity than the target, copy the data and free rhs buffers
280 if(rhs.sso.set || capacity() > rhs.capacity()) {
281 memmove(buffer(), rhs.buffer(), rhs_len);
282 setlen(rhs_len);
283 rhs.invalidate();
284 return;
285 }
286
287 // We don't have enough space so perform a pointer swap
288 if(!sso.set) {
289 free(ptr.buffer);
290 }
291 sso.set = false;
292 ptr = rhs.ptr;
293 // Can't use rhs.invalidate here as it would free the buffer
294 rhs.ptr.buffer = nullptr;
295 rhs.ptr.capacity = 0;
296 rhs.ptr.len = 0;
297}
298
299String& String::operator=(const String& rhs)
300{

Callers

nothing calls this directly

Calls 6

freeFunction · 0.85
bufferMethod · 0.80
invalidateMethod · 0.80
isNullMethod · 0.45
lengthMethod · 0.45
capacityMethod · 0.45

Tested by

no test coverage detected