From 0d226f3148b0bbb5c83d93add99c66399fa77a8b Mon Sep 17 00:00:00 2001 From: rexy712 Date: Tue, 28 Jul 2020 09:08:05 -0700 Subject: [PATCH] Update to work with new librexy allocators --- rjp++/include/string.hpp | 15 +++++++++------ rjp++/src/allocator.cpp | 11 +++-------- rjp++/src/string.cpp | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/rjp++/include/string.hpp b/rjp++/include/string.hpp index dda7dde..4b7f8d5 100644 --- a/rjp++/include/string.hpp +++ b/rjp++/include/string.hpp @@ -27,13 +27,16 @@ namespace rjp{ namespace detail{ struct allocator { - static void free(void* data); - static void* allocate(size_t size); - static void* copy(const void* data, size_t len); + using size_type = size_t; + using pointer = char*; + using const_pointer = const char*; + + char* allocate(size_type n); + void deallocate(pointer data, size_type n); }; } - class string : public rexy::string_intermediary + class string : public rexy::basic_string { public: string(const string&) = default; @@ -41,9 +44,9 @@ namespace rjp{ string& operator=(const string&) = default; string& operator=(string&&) = default; - using rexy::string_intermediary::string_intermediary; + using rexy::basic_string::basic_string; string(RJP_value* r); - using rexy::string_intermediary::operator=; + using rexy::basic_string::operator=; string& operator=(RJP_value* r); }; diff --git a/rjp++/src/allocator.cpp b/rjp++/src/allocator.cpp index af1f594..db8c773 100644 --- a/rjp++/src/allocator.cpp +++ b/rjp++/src/allocator.cpp @@ -21,15 +21,10 @@ #include //memcpy namespace rjp::detail{ - void allocator::free(void* data){ + void allocator::deallocate(pointer data, size_type){ rjp_free(data); } - void* allocator::allocate(size_t size){ - return rjp_alloc(size); - } - void* allocator::copy(const void* data, size_t len){ - char* tmp = reinterpret_cast(allocate(len)); - memcpy(tmp, data, len); - return tmp; + auto allocator::allocate(size_type size) -> pointer{ + return reinterpret_cast(rjp_alloc(size)); } } diff --git a/rjp++/src/string.cpp b/rjp++/src/string.cpp index e7a0cc1..0e69bb5 100644 --- a/rjp++/src/string.cpp +++ b/rjp++/src/string.cpp @@ -24,7 +24,7 @@ namespace rjp{ string::string(RJP_value* r): - rexy::string_intermediary(rexy::steal(r ? rjp_get_string(r)->value : nullptr), + rexy::basic_string(rexy::steal(r ? rjp_get_string(r)->value : nullptr), r ? rjp_get_string(r)->length : 0, r ? rjp_get_string(r)->length : 0) {