From db18f6c79af679fcd07c75e3355639ae52da78f7 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Fri, 7 Feb 2020 23:53:00 +0800 Subject: [PATCH] Address review simplify code --- src/core/file_sys/layered_fs.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/core/file_sys/layered_fs.cpp b/src/core/file_sys/layered_fs.cpp index 80719d3fa..65ececd31 100644 --- a/src/core/file_sys/layered_fs.cpp +++ b/src/core/file_sys/layered_fs.cpp @@ -306,18 +306,10 @@ void LayeredFS::PrepareBuild(Directory& current) { // Implementation from 3dbrew u32 CalcHash(const std::string& name, u32 parent_offset) { u32 hash = parent_offset ^ 123456789; - std::u16string u16name = Common::UTF8ToUTF16(name); - std::vector tmp_buffer(u16name.size()); - std::transform(u16name.begin(), u16name.end(), tmp_buffer.begin(), [](char16_t character) { - return static_cast(static_cast(character)); - }); - - std::vector buffer(tmp_buffer.size() * 2); - std::memcpy(buffer.data(), tmp_buffer.data(), buffer.size()); - for (std::size_t i = 0; i < buffer.size(); i += 2) { + for (char16_t c : u16name) { hash = (hash >> 5) | (hash << 27); - hash ^= static_cast((buffer[i]) | (buffer[i + 1] << 8)); + hash ^= static_cast(c); } return hash; }