Quellcode durchsuchen

When concat is same string to string, use memcpy, allows for re-alloc to move string on growth

https://forum.pjrc.com/threads/35688-Something-wrong-with-Adding-a-String-to-itself!?p=111109#post111109
main
Defragster vor 8 Jahren
Ursprung
Commit
00438a66ed
1 geänderte Dateien mit 12 neuen und 1 gelöschten Zeilen
  1. +12
    -1
      teensy3/WString.cpp

+ 12
- 1
teensy3/WString.cpp Datei anzeigen

@@ -248,8 +248,19 @@ String & String::append(const String &s)
String & String::append(const char *cstr, unsigned int length)
{
unsigned int newlen = len + length;
bool self = false;
unsigned int buffer_offset;
if ( (cstr >= buffer) && (cstr < (buffer+len) ) ) {
self = true;
buffer_offset = (unsigned int)(cstr-buffer);
}
if (length == 0 || !reserve(newlen)) return *this;
strcpy(buffer + len, cstr);
if ( self ) {
memcpy(buffer + len, buffer+buffer_offset, length);
buffer[newlen] = 0;
}
else
strcpy(buffer + len, cstr);
len = newlen;
return *this;
}

Laden…
Abbrechen
Speichern