From 1990aaf6cd6cdeb5acdf4af0b9f281fea62e41ed Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 11 Apr 2025 17:42:59 +0200 Subject: quickjs: disable JSValueConst distinction in release mode Regrettably, Nim implements converters using procedures instead of templates, so with JSValueConst it will gladly generate a gazillion pointless function calls for the linker to optimize away. Since JSValueConst itself is just a development tool, it's fine to disable in release mode. --- lib/monoucha0/monoucha/quickjs.nim | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'lib/monoucha0') diff --git a/lib/monoucha0/monoucha/quickjs.nim b/lib/monoucha0/monoucha/quickjs.nim index 883806c9..fff4d291 100644 --- a/lib/monoucha0/monoucha/quickjs.nim +++ b/lib/monoucha0/monoucha/quickjs.nim @@ -48,10 +48,12 @@ const ## all tags with a reference count are negative when sizeof(int) < sizeof(int64): {.passc: "-DJS_NAN_BOXING".} - type - JSValue* {.importc, header: qjsheader.} = distinct uint64 + type JSValue* {.importc, header: qjsheader.} = distinct uint64 - JSValueConst* {.importc: "JSValueConst".} = distinct JSValue + when defined(debug): + type JSValueConst* {.importc: "JSValueConst".} = distinct JSValue + else: + type JSValueConst* = JSValue template JS_VALUE_GET_TAG*(v: JSValueConst): int32 = cast[int32](cast[uint64](v) shr 32) @@ -74,13 +76,20 @@ else: u*: JSValueUnion tag*: int64 - JSValueConst* {.importc: "JSValueConst".} = distinct JSValue + when defined(debug): + type JSValueConst* {.importc: "JSValueConst".} = distinct JSValue + else: + type JSValueConst* = JSValue template JS_VALUE_GET_TAG*(v: JSValueConst): int32 = cast[int32](JSValue(v).tag) - template JS_VALUE_GET_PTR*(v: JSValueConst): pointer = - cast[pointer](JSValue(v).u) + when defined(debug): + template JS_VALUE_GET_PTR*(v: JSValueConst): pointer = + cast[pointer](JSValue(v).u) + else: + template JS_VALUE_GET_PTR*(v: JSValueConst): pointer = + cast[pointer](v.u) template JS_MKVAL*(t, val: untyped): JSValue = JSValue(u: JSValueUnion(`int32`: val), tag: t) @@ -286,16 +295,18 @@ type proc `==`*(a, b: JSValue): bool {.error.} = discard -proc `==`*(a, b: JSValueConst): bool {.error.} = - discard +when defined(debug): + proc `==`*(a, b: JSValueConst): bool {.error.} = + discard func `==`*(a, b: JSAtom): bool {.borrow.} -converter toJSValueConst*(val: JSValue): JSValueConst = - JSValueConst(val) +when defined(debug): + converter toJSValueConst*(val: JSValue): JSValueConst = + JSValueConst(val) -converter toJSValueConstArray*(val: JSValueArray): JSValueConstArray = - JSValueConstArray(val) + converter toJSValueConstArray*(val: JSValueArray): JSValueConstArray = + JSValueConstArray(val) converter toJSClassID*(e: JSClassEnum): JSClassID {.inline.} = JSClassID(e) -- cgit