diff --git a/include/cow.h b/include/cow.h index fc9abe9..6c6b370 100644 --- a/include/cow.h +++ b/include/cow.h @@ -24,14 +24,19 @@ cow_t* cow_clone(const cow_t* cow); int cow_is_fake(const cow_t* cow); /// Get the size of this cow area. size_t cow_size(const cow_t* cow); + /// Get the size of this cow area by assuming layout. This should work assuming "cow_t.h"'s build assertions didn't fail and avoids an extra call. +/// XXX: Deprecated function unpon seeing preferable codegen for using `cow_size()` over this. Use `cow_size()` instead. +static inline #ifdef _COW_NO_ASSUME_ABI -#define cow_size_unsafe(v) cow_size(v) +#define _cow_size_unsafe(v) cow_size(v) #else // XXX: This macro is *VERY* ABI sensitive. This shouldn't be used if the ABI has changed since the build of libcow's `cow_t.h` passed its static assertions in *both* the C and C++ implementations. // The C++ API uses this by default for its `Cow::size()` function. -#define cow_size_unsafe(v) *(((size_t*)(v))+1) +#define _cow_size_unsafe(v) (*(((size_t*)(v))+1)) + __attribute__((deprecated)) #endif + size_t cow_size_unsafe(const cow_t* v) { return _cow_size_unsafe(v); } /// Get the `void*` pointer to the start of the area. #define cow_ptr(v) (*((void**)(v))) diff --git a/include/cow.hpp b/include/cow.hpp index 53973e0..70c6e15 100644 --- a/include/cow.hpp +++ b/include/cow.hpp @@ -27,7 +27,9 @@ struct Cow { /// /// Note: This behaviour can be diabled by building with `-DCOW_NO_ASSUME_ABI`. In this case, this function calls out to the C API to determine the size. /// There is also likely no benefit using this over `size()` in LTO enabled builds. - inline size_t size_unsafe() const { return cow_size_unsafe(get_raw()); } + /// + /// XXX: Deprecated function for now. It seems `size()` offers better codegen on LTO and non-LTO enabled builds. + [[deprecated]] inline size_t size_unsafe() const { return _cow_size_unsafe(get_raw()); } inline unsigned char* as_bytes() { return (unsigned char*)area(); } inline const unsigned char* as_bytes() const { return (const unsigned char*)area(); } diff --git a/src/test/main.cpp b/src/test/main.cpp index 7f6ba64..6878d99 100644 --- a/src/test/main.cpp +++ b/src/test/main.cpp @@ -6,11 +6,13 @@ int main() { Cow real(4096); + printf("Fast size: %lu, slow size: %lu\n", real.size_unsafe(), real.size()); Cow::Fake clone = real; { Cow::Fake clone2 = clone; } + if(0) cow_size_unsafe(NULL); return 0; } diff --git a/vgcore.31455 b/vgcore.31455 new file mode 100644 index 0000000..dccfbc7 Binary files /dev/null and b/vgcore.31455 differ