From 283f2241f7ca5d5590f25c1218d11a775b8a47d3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 27 Jul 2023 19:51:30 +0100 Subject: Remove need for C memory management with STL backing store --- icespider/unittests/testPerf.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/icespider/unittests/testPerf.cpp b/icespider/unittests/testPerf.cpp index 1c7aed4..027f327 100644 --- a/icespider/unittests/testPerf.cpp +++ b/icespider/unittests/testPerf.cpp @@ -30,26 +30,21 @@ public: }; // NOLINTNEXTLINE(hicpp-special-member-functions) -class CharPtrPtrArray : public std::vector { +class CharPtrPtrArray : public std::vector { public: explicit CharPtrPtrArray(const std::filesystem::path & p) { - reserve(40); std::ifstream f(p); - while (f.good()) { - std::string line; - std::getline(f, line, '\n'); - push_back(strdup(line.c_str())); + for (std::string line; getline(f, line);) { + lines.emplace_back(line); } + std::transform(lines.begin(), lines.end(), std::back_inserter(*this), [](const auto & s) { + return s.c_str(); + }); } - ~CharPtrPtrArray() - { - for (const auto & e : *this) { - // NOLINTNEXTLINE(hicpp-no-malloc) - free(e); - } - } +private: + std::vector lines; }; class CoreFixture : public IceSpider::CoreWithDefaultRouter, public benchmark::Fixture { }; -- cgit v1.2.3