about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-04-08 02:55:08 +0200
committerbptato <nincsnevem662@gmail.com>2024-04-08 02:55:08 +0200
commit28f20005d69fe35282501861f088bae655a39acd (patch)
tree59ead141f2358627a558b4d734d6c304eee6a577
parentdef6f3e5c28974063b650db194a0c055d4dea685 (diff)
downloadchawan-28f20005d69fe35282501861f088bae655a39acd.tar.gz
Remove unnecessary std/math imports
-rw-r--r--src/img/png.nim8
-rw-r--r--src/types/url.nim7
2 files changed, 6 insertions, 9 deletions
diff --git a/src/img/png.nim b/src/img/png.nim
index 047a080f..27482e63 100644
--- a/src/img/png.nim
+++ b/src/img/png.nim
@@ -1,5 +1,3 @@
-import std/math
-
 import bindings/zlib
 import img/bitmap
 import types/color
@@ -11,7 +9,7 @@ type PNGWriter = object
   outlen: int
 
 func pngInt(i: uint32): auto =
-  doAssert i < uint32(2) ^ 31
+  doAssert i < 0x80000000u32
   return i.toBytesBE()
 
 func oq(writer: PNGWriter): ptr UncheckedArray[uint8] =
@@ -28,7 +26,7 @@ proc writeInt(writer: var PNGWriter, i: uint32) =
   writer.writeStr(i.toBytesBE())
 
 proc writePngInt(writer: var PNGWriter, i: uint32) =
-  doAssert i < uint32(2) ^ 31
+  doAssert i < 0x80000000u32
   writer.writeInt(i)
 
 proc writeChunk[T](writer: var PNGWriter, t: string, data: T) =
@@ -172,7 +170,7 @@ template readU32(reader: var PNGReader): uint32 =
 
 template readPNGInt(reader: var PNGReader): uint32 =
   let x = reader.readU32()
-  if x >= uint32(2) ^ 31:
+  if x >= 0x80000000u32:
     reader.err "int too large"
   x
 
diff --git a/src/types/url.nim b/src/types/url.nim
index 93a63617..10394020 100644
--- a/src/types/url.nim
+++ b/src/types/url.nim
@@ -1,6 +1,5 @@
 # See https://url.spec.whatwg.org/#url-parsing.
 import std/algorithm
-import std/math
 import std/options
 import std/strutils
 import std/tables
@@ -209,13 +208,13 @@ func parseIpv4(input: string): Option[uint32] =
       if i != high(parts):
         return none(uint32)
     numbers.add(num)
-  if numbers[^1] >= 256^(5-numbers.len):
+  if numbers[^1] >= 1 shl ((5 - numbers.len) * 8):
     return none(uint32)
   var ipv4 = uint32(numbers[^1])
   discard numbers.pop()
   for i in 0..numbers.high:
     let n = uint32(numbers[i])
-    ipv4 += n * (256u32 ^ (3 - i))
+    ipv4 += n * (1u32 shl ((3 - i) * 8))
   return ipv4.some
 
 const ForbiddenHostChars = {
@@ -836,7 +835,7 @@ func serializeip(ipv4: uint32): string =
     result = $(n mod 256) & result
     if i != 4:
       result = '.' & result
-    n = n.floorDiv 256u32
+    n = n div 256
   assert n == 0
 
 func findZeroSeq(ipv6: array[8, uint16]): int =