From 05231d8b08f7d473a4c4cf7640227f41de44ac23 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 20 Jul 2018 21:40:13 -0400 Subject: vfs: Amend constness on pointers in WriteBytes() and WriteArrays() member functions to be const qualified These functions don't modify the data being pointed to, so these can be pointers to const data --- src/core/file_sys/vfs.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core/file_sys/vfs.h') diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index a5213e0cc..edd689c68 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h @@ -93,7 +93,7 @@ struct VfsFile : NonCopyable { // Writes an array of type T, size number_elements to offset in file. // Returns the number of bytes (sizeof(T)*number_elements) written successfully. template - size_t WriteArray(T* data, size_t number_elements, size_t offset = 0) { + size_t WriteArray(const T* data, size_t number_elements, size_t offset = 0) { static_assert(std::is_trivially_copyable::value, "Data type must be trivially copyable."); @@ -103,10 +103,10 @@ struct VfsFile : NonCopyable { // Writes size bytes starting at memory location data to offset in file. // Returns the number of bytes written successfully. template - size_t WriteBytes(T* data, size_t size, size_t offset = 0) { + size_t WriteBytes(const T* data, size_t size, size_t offset = 0) { static_assert(std::is_trivially_copyable::value, "Data type must be trivially copyable."); - return Write(reinterpret_cast(data), size, offset); + return Write(reinterpret_cast(data), size, offset); } // Writes one object of type T to offset in file. -- cgit v1.2.3 From dd09439feec14362b8d88c6fad662c9996426b67 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 20 Jul 2018 21:45:20 -0400 Subject: vfs: Use variable template variants of std::is_trivially_copyable Provides the same behavior, but with less writing --- src/core/file_sys/vfs.h | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/core/file_sys/vfs.h') diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index edd689c68..d108ab1f4 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h @@ -59,8 +59,7 @@ struct VfsFile : NonCopyable { // Returns the number of bytes (sizeof(T)*number_elements) read successfully. template size_t ReadArray(T* data, size_t number_elements, size_t offset = 0) const { - static_assert(std::is_trivially_copyable::value, - "Data type must be trivially copyable."); + static_assert(std::is_trivially_copyable_v, "Data type must be trivially copyable."); return Read(reinterpret_cast(data), number_elements * sizeof(T), offset); } @@ -69,8 +68,7 @@ struct VfsFile : NonCopyable { // Returns the number of bytes read successfully. template size_t ReadBytes(T* data, size_t size, size_t offset = 0) const { - static_assert(std::is_trivially_copyable::value, - "Data type must be trivially copyable."); + static_assert(std::is_trivially_copyable_v, "Data type must be trivially copyable."); return Read(reinterpret_cast(data), size, offset); } @@ -78,8 +76,7 @@ struct VfsFile : NonCopyable { // Returns the number of bytes read successfully (sizeof(T)). template size_t ReadObject(T* data, size_t offset = 0) const { - static_assert(std::is_trivially_copyable::value, - "Data type must be trivially copyable."); + static_assert(std::is_trivially_copyable_v, "Data type must be trivially copyable."); return Read(reinterpret_cast(data), sizeof(T), offset); } @@ -94,9 +91,7 @@ struct VfsFile : NonCopyable { // Returns the number of bytes (sizeof(T)*number_elements) written successfully. template size_t WriteArray(const T* data, size_t number_elements, size_t offset = 0) { - static_assert(std::is_trivially_copyable::value, - "Data type must be trivially copyable."); - + static_assert(std::is_trivially_copyable_v, "Data type must be trivially copyable."); return Write(data, number_elements * sizeof(T), offset); } @@ -104,8 +99,7 @@ struct VfsFile : NonCopyable { // Returns the number of bytes written successfully. template size_t WriteBytes(const T* data, size_t size, size_t offset = 0) { - static_assert(std::is_trivially_copyable::value, - "Data type must be trivially copyable."); + static_assert(std::is_trivially_copyable_v, "Data type must be trivially copyable."); return Write(reinterpret_cast(data), size, offset); } @@ -113,8 +107,7 @@ struct VfsFile : NonCopyable { // Returns the number of bytes written successfully (sizeof(T)). template size_t WriteObject(const T& data, size_t offset = 0) { - static_assert(std::is_trivially_copyable::value, - "Data type must be trivially copyable."); + static_assert(std::is_trivially_copyable_v, "Data type must be trivially copyable."); return Write(&data, sizeof(T), offset); } -- cgit v1.2.3 From 894b0de0f2cd15655726ae885b44b030711328a3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 20 Jul 2018 21:51:28 -0400 Subject: vfs: Make WriteBytes() overload taking a std::vector pass the std::vector by const reference Given the data is intended to be directly written, there's no need to take the std::vector by value and copy the data. --- src/core/file_sys/vfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/file_sys/vfs.h') diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index d108ab1f4..db3c77eac 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h @@ -85,7 +85,7 @@ struct VfsFile : NonCopyable { virtual bool WriteByte(u8 data, size_t offset = 0); // Writes a vector of bytes to offset in file and returns the number of bytes successfully // written. - virtual size_t WriteBytes(std::vector data, size_t offset = 0); + virtual size_t WriteBytes(const std::vector& data, size_t offset = 0); // Writes an array of type T, size number_elements to offset in file. // Returns the number of bytes (sizeof(T)*number_elements) written successfully. -- cgit v1.2.3