diff options
| author | bptato <nincsnevem662@gmail.com> | 2023-09-13 17:30:00 +0200 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2023-09-13 17:30:00 +0200 |
| commit | 4dc63cee8b20dcba3984019d8fa8221d8117ac35 (patch) | |
| tree | 592fb0a14686c1c403590dd808db6b5bc312ed0f /src | |
| parent | 19caa22e7e5006ae32b49ba6250738cfd3781548 (diff) | |
| download | chawan-4dc63cee8b20dcba3984019d8fa8221d8117ac35.tar.gz | |
toml: do not stream input
It is more efficient to just read the whole file into memory than
to... read the whole file into memory, but one piece at a time,
while calling the rather slow readLine function for each chunk.
(Also, configuration files are rather small, so even a proper streaming
implementation would be pointless.)
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/toml.nim | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/src/config/toml.nim b/src/config/toml.nim index 4fcf6d9b..82e5aedd 100644 --- a/src/config/toml.nim +++ b/src/config/toml.nim @@ -25,7 +25,6 @@ type filename: string at: int line: int - stream: Stream buf: string root: TomlTable node: TomlNode @@ -100,8 +99,6 @@ proc reconsume(state: var TomlParser) = dec state.at proc has(state: var TomlParser, i: int = 0): bool = - if state.at + i >= state.buf.len and not state.stream.atEnd(): - state.buf &= state.stream.readLine() & '\n' return state.at + i < state.buf.len proc consumeEscape(state: var TomlParser, c: char): Result[Rune, TomlError] = @@ -536,7 +533,7 @@ proc consumeValue(state: var TomlParser): TomlResult = proc parseToml*(inputStream: Stream, filename = "<input>"): TomlResult = var state: TomlParser - state.stream = inputStream + state.buf = inputStream.readAll() state.line = 1 state.root = TomlTable() state.filename = filename |