about summary refs log tree commit diff stats
path: root/src/css
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-09-06 20:28:36 +0200
committerbptato <nincsnevem662@gmail.com>2024-09-06 20:31:17 +0200
commit357f25e8145e194367edda8accdffa3bd752797e (patch)
tree76d667df1879b4be1ae3f915d8489b87bb0e9f6d /src/css
parentef5d188e05d4895125ad059f5518f9c8ff83bef5 (diff)
downloadchawan-357f25e8145e194367edda8accdffa3bd752797e.tar.gz
twtstr: type erase binarySearch instantiation
Do it like parseEnumNoCase0, so we no longer instantiate a gazillion
different binary searches for the same type.

While we're at it, make matchNameProduction's searchInMap use uint32
too.
Diffstat (limited to 'src/css')
-rw-r--r--src/css/cssvalues.nim14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/css/cssvalues.nim b/src/css/cssvalues.nim
index f8a50723..4b1cc957 100644
--- a/src/css/cssvalues.nim
+++ b/src/css/cssvalues.nim
@@ -768,17 +768,19 @@ template isToken(cval: CSSComponentValue): bool =
 template getToken(cval: CSSComponentValue): CSSToken =
   CSSToken(cval)
 
-func parseIdent(map: openArray[IdentMapItem]; cval: CSSComponentValue):
-    Opt[int] =
+func parseIdent(map: openArray[IdentMapItem]; cval: CSSComponentValue): int =
   if isToken(cval):
     let tok = getToken(cval)
     if tok.tokenType == cttIdent:
       return map.parseEnumNoCase0(tok.value)
-  return err()
+  return -1
 
 func parseIdent[T: enum](cval: CSSComponentValue): Opt[T] =
   const IdentMap = getIdentMap(T)
-  return ok(cast[T](?IdentMap.parseIdent(cval)))
+  let i = IdentMap.parseIdent(cval)
+  if i != -1:
+    return ok(T(i))
+  return err()
 
 func cssLength(val: float64; unit: string): Opt[CSSLength] =
   let u = ?parseEnumNoCase[CSSUnit](unit)
@@ -1028,7 +1030,9 @@ func cssFontWeight(cval: CSSComponentValue): Opt[int] =
         "lighter": 400,
         "bolder": 700
       }
-      return FontWeightMap.parseIdent(cval)
+      let i = FontWeightMap.parseIdent(cval)
+      if i != -1:
+        return ok(i)
     elif tok.tokenType == cttNumber:
       if tok.nvalue in 1f64..1000f64:
         return ok(int(tok.nvalue))