diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-02-13 20:22:05 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-02-13 20:22:05 +0100 |
| commit | 8f43f6c70150fe0ff3fff1b152f69f13c9605800 (patch) | |
| tree | 88f0a18c1ad2026b5bb620fd02d82aa0de47b1e5 /src/types | |
| parent | 7ad94b17c94ccd9e63609ffd4ecde7b82f728eaa (diff) | |
| download | chawan-8f43f6c70150fe0ff3fff1b152f69f13c9605800.tar.gz | |
csstree, layout: more refactoring
Base InlineBox is a fair bit smaller now, and (most) strings are
cached using RefString.
Diffstat (limited to 'src/types')
| -rw-r--r-- | src/types/refstring.nim | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/types/refstring.nim b/src/types/refstring.nim new file mode 100644 index 00000000..55c98530 --- /dev/null +++ b/src/types/refstring.nim @@ -0,0 +1,26 @@ +import monoucha/fromjs +import monoucha/javascript +import monoucha/tojs +import types/opt + +type RefString* = ref object + s*: string + +proc newRefString*(s: sink string): RefString = + return RefString(s: s) + +converter `$`*(rs: RefString): lent string = + rs.s + +template `&=`*(rs: var RefString; ss: string) = + rs.s &= ss + +proc toJS*(ctx: JSContext; rs: RefString): JSValue = + return ctx.toJS($rs) + +proc fromJS*(ctx: JSContext; val: JSValue; rs: out RefString): Opt[void] = + rs = RefString() + if ctx.fromJS(val, rs.s).isNone: + rs = nil + return err() + return ok() |