From 3e4abb9f049c66c08c23797190b5c2bc44f2862e Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 3 May 2021 21:32:38 +0200 Subject: [PATCH] Avoid copy from vector to string Read directly into a string. --- components/nif/nifstream.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/nif/nifstream.hpp b/components/nif/nifstream.hpp index cee98dd831..1c4407afd9 100644 --- a/components/nif/nifstream.hpp +++ b/components/nif/nifstream.hpp @@ -142,11 +142,9 @@ public: ///Read in a string of the given length std::string getSizedString(size_t length) { - std::vector str(length + 1, 0); - + std::string str(length, '\0'); inp->read(str.data(), length); - - return str.data(); + return str; } ///Read in a string of the length specified in the file std::string getSizedString()