News for hackers. Stuff that matters.
Re:Effortless Performance Improvements in C++: std:vector by returningfory2 on Wednesday March 08, 2023 @06:22PM (#35076164)
A complementary idea is to reuse the vector of strings across different calls to `tokenize`. The main loop in the code is of the form:

    {
        std::vector<std::string> tokens = tokenize(line);
        // do work with tokens
    }
which you could change to

    std::vector<std::string> tokens;
    {
        tokens.clear();
        tokenize(line, &tokens);
        // do work with tokens
    }
Combined with your suggestion to use std::string_view, this would mean only O(1) allocations across the program for this part of the code.

There are no comments on this comment yet.