Skip to content

Commit

Permalink
Don't reserve 4096 lines for justifiedEntryValueText
Browse files Browse the repository at this point in the history
  • Loading branch information
zorael committed Jan 27, 2024
1 parent e96bf04 commit ca253bb
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions source/lu/serialisation.d
Original file line number Diff line number Diff line change
Expand Up @@ -1044,17 +1044,19 @@ bara blaawp,oorgle,blaawp`;
+/
string justifiedEntryValueText(const string origLines) pure
{
import lu.numeric : getMultipleOf;
import lu.string : stripped;
import std.algorithm.comparison : max;
import std.algorithm.iteration : splitter;
import std.algorithm.iteration : joiner, splitter;
import std.array : Appender;

if (!origLines.length) return string.init;

enum decentReserve = 4096;
enum decentReserveOfLines = 256;
enum decentReserveOfChars = 4096;

Appender!(string[]) unjustified;
unjustified.reserve(decentReserve);
unjustified.reserve(decentReserveOfLines);
size_t longestEntryLength;

foreach (immutable rawline; origLines.splitter("\n"))
Expand Down Expand Up @@ -1094,11 +1096,8 @@ string justifiedEntryValueText(const string origLines) pure
}
}

import lu.numeric : getMultipleOf;
import std.algorithm.iteration : joiner;

Appender!(char[]) justified;
justified.reserve(decentReserve);
justified.reserve(decentReserveOfChars);

assert((longestEntryLength > 0), "No longest entry; is the struct empty?");
assert((unjustified.data.length > 0), "Unjustified data is empty");
Expand Down

0 comments on commit ca253bb

Please sign in to comment.