diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-01-18 14:51:56 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-01-18 14:51:56 +0100 |
| commit | 74f7ff805a5de7f1394f9a9ca5c3c3f0aa07caa3 (patch) | |
| tree | 6d55c6c4321086c41d75eb124806a32455c3f37f | |
| parent | 4c2028eb6d85b93fac25cc5ba2cdbb2ba0aaf7ff (diff) | |
| download | chawan-74f7ff805a5de7f1394f9a9ca5c3c3f0aa07caa3.tar.gz | |
dom: optimize
We'll see if the borrow checker actually works :)
| -rw-r--r-- | src/html/catom.nim | 8 | ||||
| -rw-r--r-- | src/html/dom.nim | 18 |
2 files changed, 16 insertions, 10 deletions
diff --git a/src/html/catom.nim b/src/html/catom.nim index 75ae5670..64e3cd2c 100644 --- a/src/html/catom.nim +++ b/src/html/catom.nim @@ -263,10 +263,10 @@ func containsIgnoreCase*(factory: CAtomFactory; aa: openArray[CAtom]; a: StaticAtom): bool = return factory.containsIgnoreCase(aa, factory.toAtom(a)) -func toStr*(factory: CAtomFactory; atom: CAtom): string = +func toStr*(factory: CAtomFactory; atom: CAtom): lent string = return factory.atomMap[int(atom)] -func toStr*(factory: CAtomFactory; sa: StaticAtom): string = +func toStr*(factory: CAtomFactory; sa: StaticAtom): lent string = return factory.toStr(factory.toAtom(sa)) func toTagType*(atom: CAtom): TagType = @@ -317,10 +317,10 @@ proc toStaticAtom*(ctx: JSContext; atom: CAtom): StaticAtom = proc toStaticAtom*(ctx: JSContext; s: string): StaticAtom = return ctx.getFactoryImpl().toStaticAtom(s) -proc toStr*(ctx: JSContext; atom: CAtom): string = +proc toStr*(ctx: JSContext; atom: CAtom): lent string = return ctx.getFactoryImpl().toStr(atom) -proc toStr*(ctx: JSContext; sa: StaticAtom): string = +proc toStr*(ctx: JSContext; sa: StaticAtom): lent string = return ctx.getFactoryImpl().toStr(sa) proc fromJS*(ctx: JSContext; val: JSValue; res: var CAtom): Opt[void] = diff --git a/src/html/dom.nim b/src/html/dom.nim index 73bd52a4..9d2ff364 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -516,7 +516,7 @@ jsDestructor(TextMetrics) jsDestructor(CSSStyleDeclaration) # Forward declarations -func attr*(element: Element; s: StaticAtom): string +func attr*(element: Element; s: StaticAtom): lent string func attrb*(element: Element; s: CAtom): bool func serializeFragment(res: var string; node: Node) func value*(option: HTMLOptionElement): string @@ -1092,13 +1092,16 @@ func document*(node: Node): Document = return Document(node) return node.internalDocument +template document*(element: Element): Document = + element.internalDocument + proc toAtom*(window: Window; atom: StaticAtom): CAtom = return window.factory.toAtom(atom) proc toAtom*(window: Window; s: string): CAtom = return window.factory.toAtom(s) -proc toStr*(window: Window; atom: CAtom): string = +proc toStr*(window: Window; atom: CAtom): lent string = return window.factory.toStr(atom) proc toAtom*(document: Document; s: string): CAtom = @@ -1110,7 +1113,7 @@ proc toAtomLower*(document: Document; s: string): CAtom = proc toAtom*(document: Document; at: StaticAtom): CAtom = return document.factory.toAtom(at) -proc toStr(document: Document; atom: CAtom): string = +proc toStr(document: Document; atom: CAtom): lent string = return document.factory.toStr(atom) proc toStaticAtom(document: Document; atom: CAtom): StaticAtom = @@ -2521,13 +2524,16 @@ proc getter(ctx: JSContext; document: Document; s: string): JSValue return ctx.toJS(child) return JS_UNINITIALIZED -func attr*(element: Element; s: CAtom): string = +func attr*(element: Element; s: CAtom): lent string = let i = element.findAttr(s) if i != -1: return element.attrs[i].value - return "" + {.cast(noSideEffect).}: + # the compiler cries if I return string literals :/ + let emptyStr {.global.} = "" + return emptyStr -func attr*(element: Element; s: StaticAtom): string = +func attr*(element: Element; s: StaticAtom): lent string = return element.attr(element.document.toAtom(s)) func attrl*(element: Element; s: StaticAtom): Option[int32] = |