diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/common/bit_cast.h | 22 | ||||
| -rw-r--r-- | src/common/virtual_buffer.h | 7 | 
3 files changed, 29 insertions, 1 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 207c7a0a6..d20e6c3b5 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -102,6 +102,7 @@ add_library(common STATIC      atomic_ops.h      detached_tasks.cpp      detached_tasks.h +    bit_cast.h      bit_field.h      bit_util.h      cityhash.cpp diff --git a/src/common/bit_cast.h b/src/common/bit_cast.h new file mode 100644 index 000000000..a32a063d1 --- /dev/null +++ b/src/common/bit_cast.h @@ -0,0 +1,22 @@ +// Copyright 2020 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <cstring> +#include <type_traits> + +namespace Common { + +template <typename To, typename From> +[[nodiscard]] std::enable_if_t<sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<From> && +                                   std::is_trivially_copyable_v<To>, +                               To> +BitCast(const From& src) noexcept { +    To dst; +    std::memcpy(&dst, &src, sizeof(To)); +    return dst; +} + +} // namespace Common diff --git a/src/common/virtual_buffer.h b/src/common/virtual_buffer.h index 078e61c77..91d430036 100644 --- a/src/common/virtual_buffer.h +++ b/src/common/virtual_buffer.h @@ -43,9 +43,14 @@ public:      }      void resize(std::size_t count) { +        const auto new_size = count * sizeof(T); +        if (new_size == alloc_size) { +            return; +        } +          FreeMemoryPages(base_ptr, alloc_size); -        alloc_size = count * sizeof(T); +        alloc_size = new_size;          base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size));      }  | 
