diff --git a/include/rexy/string_base.tpp b/include/rexy/string_base.tpp index 8d228e0..4ebae7b 100644 --- a/include/rexy/string_base.tpp +++ b/include/rexy/string_base.tpp @@ -20,10 +20,9 @@ #define REXY_STRING_BASE_TPP #include //forward, move, swap, etc -#include //memcpy #include //strlen, strcpy -#include "utility.hpp" //max +#include "utility.hpp" //max, memcpy #include "detail/string_appender.hpp" #include "algorithm.hpp" #include "compat/to_address.hpp" @@ -88,7 +87,7 @@ namespace rexy{ this->set_islong_flag(true); pointer raw = this->set_long_ptr(this->allocate(sizeof(value_type)*(cap+1))); if(data) - memcpy(raw, data, sizeof(value_type)*len); + rexy::memcpy(raw, data, sizeof(value_type)*len); raw[len] = 0; this->set_long_length(len); this->set_long_capacity(cap); @@ -96,7 +95,7 @@ namespace rexy{ this->set_islong_flag(false); pointer raw = this->set_short_ptr(); if(data) - memcpy(raw, data, sizeof(value_type)*len); + rexy::memcpy(raw, data, sizeof(value_type)*len); raw[len] = 0; this->set_short_length(len); this->set_short_capacity(cap); @@ -164,7 +163,7 @@ namespace rexy{ noexcept(is_nothrow_allocator_v): detail::hasallocator(b) { - _copy_construct_string(b.get(), b.length(), b.capacity()); + _copy_construct_string(b.get(), b.length(), b.length()); } template constexpr basic_string::basic_string(basic_string&& s)noexcept: @@ -174,7 +173,7 @@ namespace rexy{ REXY_CPP20_CONSTEXPR basic_string::basic_string(const string_base& b) noexcept(is_nothrow_allocator_v) { - _copy_construct_string(b.get(), b.length(), b.capacity()); + _copy_construct_string(b.get(), b.length(), b.length()); } //dtor @@ -192,12 +191,13 @@ namespace rexy{ noexcept(is_nothrow_allocator_v) { if(s.length() < this->capacity()){ - memcpy(this->get_pointer(), s.get_pointer(), sizeof(value_type)*(s.length()+1)); + rexy::memcpy(this->get_pointer(), s.get_pointer(), sizeof(value_type)*(s.length()+1)); this->set_length(s.length()); return *this; + }else{ + basic_string tmp(s); + return (*this = std::move(tmp)); } - basic_string tmp(s); - return (*this = std::move(tmp)); } template constexpr basic_string& basic_string::operator=(basic_string&& s)noexcept{ @@ -270,7 +270,7 @@ namespace rexy{ pointer raw = this->get_pointer(); if(mylen+len <= mycap){ - memcpy(raw+mylen, data, sizeof(value_type)*len); + rexy::memcpy(raw+mylen, data, sizeof(value_type)*len); this->set_length(mylen+len); raw[mylen+len] = 0; }else{ @@ -336,7 +336,7 @@ namespace rexy{ size_type len = this->get_short_length(); pointer raw = this->get_short_ptr(); pointer retval = this->allocate(sizeof(value_type)*len+1); - memcpy(retval, raw, sizeof(value_type)*len); + rexy::memcpy(retval, raw, sizeof(value_type)*len); retval[len] = 0; raw[0] = 0; this->set_short_length(0); @@ -361,7 +361,7 @@ namespace rexy{ if(len <= this->length()){ this->set_length(len); pointer raw = this->get_pointer(); - memcpy(raw, s, sizeof(value_type)*len); + rexy::memcpy(raw, s, sizeof(value_type)*len); raw[len] = 0; return *this; }