Explorar el Código

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 hace 8 años
padre
commit
00438a66ed
Se han modificado 1 ficheros con 12 adiciones y 1 borrados
  1. +12
    -1
      teensy3/WString.cpp

+ 12
- 1
teensy3/WString.cpp Ver fichero

@@ -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;
}

Cargando…
Cancelar
Guardar