diff options
author | bptato <nincsnevem662@gmail.com> | 2024-12-03 18:28:36 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-12-03 18:28:51 +0100 |
commit | 772b0a79e565a9c413766a0eb6b760d8d5cdd870 (patch) | |
tree | 8a806ee76c87e25b013548a0de67a668bb458362 /src/main.nim | |
parent | 483917aa450882aaf523640f5ba8660d746b4d3f (diff) | |
download | chawan-772b0a79e565a9c413766a0eb6b760d8d5cdd870.tar.gz |
toml, config: skip copying buf, use PosixStream
one std/streams less I used mmap for reading the user config. It shouldn't matter in any realistically sized config, but who knows.
Diffstat (limited to 'src/main.nim')
-rw-r--r-- | src/main.nim | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/main.nim b/src/main.nim index ccf28703..7d8302e7 100644 --- a/src/main.nim +++ b/src/main.nim @@ -3,7 +3,6 @@ import version import std/options import std/os import std/posix -import std/streams import chagashi/charset import config/chapath @@ -206,17 +205,20 @@ const defaultConfig = staticRead"res/config.toml" proc initConfig(ctx: ParamParseContext; config: Config; warnings: var seq[string]): Err[string] = - let fs = openConfig(config.dir, ctx.configPath) - if fs == nil and ctx.configPath.isSome: + let ps = openConfig(config.dir, ctx.configPath) + if ps == nil and ctx.configPath.isSome: # The user specified a non-existent config file. return err("Failed to open config file " & ctx.configPath.get) putEnv("CHA_CONFIG_DIR", config.dir) ?config.parseConfig("res", defaultConfig, warnings) when defined(debug): - if (let fs = newFileStream(getCurrentDir() / "res/config.toml"); fs != nil): - ?config.parseConfig(getCurrentDir(), fs.readAll(), warnings) - if fs != nil: - ?config.parseConfig(config.dir, fs.readAll(), warnings) + if (let ps = newPosixStream(getCurrentDir() / "res/config.toml"); + ps != nil): + ?config.parseConfig(getCurrentDir(), ps.recvAll(), warnings) + if ps != nil: + let src = ps.recvDataLoopOrMmap() + ?config.parseConfig(config.dir, src.toOpenArray(), warnings) + deallocMem(src) for opt in ctx.opts: ?config.parseConfig(getCurrentDir(), opt, warnings, laxnames = true) config.css.stylesheet &= ctx.stylesheet |