From e7a9412479c5c338d6450718fb7e4304fe693700 Mon Sep 17 00:00:00 2001 From: modeco80 Date: Thu, 16 Jan 2025 02:14:26 -0500 Subject: [PATCH] libeuropa/io: Clean up `ReadPString()` While it's moot since we don't read in any hot paths, std::istream already has `read(chars, len)`, which means we don't need to reinvent it poorly. It's cleaner code as well. --- src/libeuropa/io/StreamUtils.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libeuropa/io/StreamUtils.cpp b/src/libeuropa/io/StreamUtils.cpp index 4ac24e3..4305c1b 100644 --- a/src/libeuropa/io/StreamUtils.cpp +++ b/src/libeuropa/io/StreamUtils.cpp @@ -54,17 +54,16 @@ namespace europa::io::impl { std::uint32_t length = static_cast(is.get()); if(length == 0) { + // TODO: is this even possible/valid? static_cast(is.get()); return ""; } + // Read the string. s.resize(length - 1); - - // Read the string - for(std::uint32_t i = 0; i < length - 1; ++i) { - s[i] = static_cast(is.get()); - } + is.read(&s[0], length-1); static_cast(is.get()); + return s; }