about summary refs log tree commit diff stats
path: root/lib/monoucha0
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-04-11 17:42:59 +0200
committerbptato <nincsnevem662@gmail.com>2025-04-11 19:04:57 +0200
commit1990aaf6cd6cdeb5acdf4af0b9f281fea62e41ed (patch)
tree31df2ebf6c00bcd2801a895aaccdd79c4aa66d11 /lib/monoucha0
parentc908f05f03bac0cbccd14ab13ea8d0df8b087611 (diff)
downloadchawan-1990aaf6cd6cdeb5acdf4af0b9f281fea62e41ed.tar.gz
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.
Diffstat (limited to 'lib/monoucha0')
-rw-r--r--lib/monoucha0/monoucha/quickjs.nim35
1 files changed, 23 insertions, 12 deletions
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)