From 1b54518988f5719cfe46092a99b11a5c7c07c757 Mon Sep 17 00:00:00 2001 From: mertcandav Date: Wed, 23 Oct 2024 12:55:42 +0300 Subject: [PATCH] compiler: take advantage of the new --opt-str optimizations --- src/julec/obj/cxx/object.jule | 5 ++-- std/bytes/bytes.jule | 4 +-- std/internal/fastbytes/fastbytes.jule | 24 ------------------ std/internal/fastbytes/fastbytes_test.jule | 29 ---------------------- std/net/ip.jule | 6 ++--- std/os/filepath/path.jule | 3 +-- 6 files changed, 7 insertions(+), 64 deletions(-) diff --git a/src/julec/obj/cxx/object.jule b/src/julec/obj/cxx/object.jule index 292870dd9..41f0c5824 100644 --- a/src/julec/obj/cxx/object.jule +++ b/src/julec/obj/cxx/object.jule @@ -16,7 +16,6 @@ use "std/os/filepath" use "std/slices" use "std/strings" use "std/time" -use "std/unsafe" const ctxParamIdent = "__f_ctx" const anonFnCtxSuffix = "_ctx" // Anon fn identifier suffix for ctx struct identifier. @@ -704,8 +703,8 @@ impl ObjectCoder { mut fIdent := strings::Builder.New(len(f.Decl.Ident)) identCoder.field(fIdent, f.Decl) - lmodel += unsafe { unsafe::BytesStr(fIdent.Buf()) } - rmodel += unsafe { unsafe::BytesStr(fIdent.Buf()) } + lmodel += str(unsafe { fIdent.Buf() }) + rmodel += str(unsafe { fIdent.Buf() }) self.ec._unsafeBinary(self.Buf, lmodel, rmodel, f.Type, f.Type, token::Id.Eqs, token::Kind.Eqs) lmodel = lmodel[:len(lmodel)-fIdent.Len()] rmodel = lmodel[:len(rmodel)-fIdent.Len()] diff --git a/std/bytes/bytes.jule b/std/bytes/bytes.jule index c72f3a386..6f00bfaef 100644 --- a/std/bytes/bytes.jule +++ b/std/bytes/bytes.jule @@ -321,9 +321,7 @@ fn Count(s: []byte, sub: []byte): int { // Reports whether two byte slices are the same length and contains same bytes. // The nil slice considered as zero-length empty slice. -fn Equal(s1: []byte, s2: []byte): bool { - ret fastbytes::Equal(s1, s2) -} +fn Equal(s1: []byte, s2: []byte): bool { ret str(s1) == str(s2) } // Replaces all sub-slices matching sub in the slice with new. // Returns same slice if n is equals to zero. diff --git a/std/internal/fastbytes/fastbytes.jule b/std/internal/fastbytes/fastbytes.jule index fa6297566..5b69aff9d 100644 --- a/std/internal/fastbytes/fastbytes.jule +++ b/std/internal/fastbytes/fastbytes.jule @@ -5,30 +5,6 @@ // Package fastbytes implements fast algorithms for byte stacks with // a minor dependencies, what a cheap algorithm package for byte stack functionalities. -// Reports whether two byte slices are the same length and contains same bytes. -// The nil slice considered as zero-length empty slice. -fn Equal(s1: []byte, s2: []byte): bool { - match { - | len(s1) != len(s2): - ret false - | len(s1) == 0: - ret true - } - end := &s1[len(s1)-1] - mut it1 := &s1[0] - mut it2 := &s2[0] - for it1 <= end { - unsafe { - if *it1 != *it2 { - ret false - } - } - it1++ - it2++ - } - ret true -} - // Returns index of first matched item with specified byte, // returns -1 if not exist any match. Starts searching at left // of slice to right. diff --git a/std/internal/fastbytes/fastbytes_test.jule b/std/internal/fastbytes/fastbytes_test.jule index 3c2c3afc1..57891c677 100644 --- a/std/internal/fastbytes/fastbytes_test.jule +++ b/std/internal/fastbytes/fastbytes_test.jule @@ -4,31 +4,12 @@ use "std/testing" -struct equalCase { - s1: []byte - s2: []byte - ok: bool -} - struct findByteCase { bytes: []byte b: byte i: int } -static casesEqual: []equalCase = [ - {[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], true}, - {[]byte("abcd üöpşç"), []byte("abcd üöpşç"), true}, - {[], [], true}, - {nil, nil, true}, - {[], nil, true}, - {[1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6], false}, - {[1, 2, 3, 4, 5], [1, 2, 3, 4], false}, - {[1, 2, 3, 4], [1, 2, 3, 4, 5], false}, - {[1, 2, 3, 4], [], false}, - {[1, 2, 3, 4], nil, false}, -] - static casesFindByte: []findByteCase = [ {[1, 2, 3, 4, 5, 6, 5, 4], 89, -1}, {[1, 2, 3, 4, 5, 6, 5, 4], 1, 0}, @@ -43,16 +24,6 @@ static casesFindLastByte: []findByteCase = [ {[1, 2, 3, 4, 5, 6, 5, 4], 5, 6}, ] -#test -fn testEqual(t: &testing::T) { - for _, case in casesEqual { - ok := Equal(case.s1, case.s2) - if ok != case.ok { - t.Errorf("expected {} for Equal({}, {}), found {}", case.ok, case.s1, case.s2, ok) - } - } -} - #test fn testFindByte(t: &testing::T) { for _, case in casesFindByte { diff --git a/std/net/ip.jule b/std/net/ip.jule index 45f1af7f0..94d89cc83 100644 --- a/std/net/ip.jule +++ b/std/net/ip.jule @@ -45,11 +45,11 @@ impl Ip { fn Eq(self, other: Ip): bool { match { | len(self.Addr) == len(other.Addr): - ret fastbytes::Equal(self.Addr, other.Addr) + ret str(self.Addr) == str(other.Addr) | len(self.Addr) == Ipv4.Len && len(other.Addr) == Ipv6.Len: - ret fastbytes::Equal(other.Addr[:12], v4InV6Prefix) && fastbytes::Equal(self.Addr, other.Addr[12:]) + ret str(other.Addr[:12]) == str(v4InV6Prefix) && str(self.Addr) == str(other.Addr[12:]) | len(self.Addr) == Ipv6.Len && len(other.Addr) == Ipv4.Len: - ret fastbytes::Equal(self.Addr[:12], v4InV6Prefix) && fastbytes::Equal(self.Addr[12:], other.Addr) + ret str(self.Addr[:12]) == str(v4InV6Prefix) && str(self.Addr[12:]) == str(other.Addr) |: ret false } diff --git a/std/os/filepath/path.jule b/std/os/filepath/path.jule index d2315855b..9d5cd8694 100644 --- a/std/os/filepath/path.jule +++ b/std/os/filepath/path.jule @@ -37,7 +37,6 @@ use "std/runtime" use "std/strings" -use "std/unsafe" // A LazyBuff is a lazily constructed path buffer. // It supports append, reading previously appended bytes, @@ -76,7 +75,7 @@ impl lazyBuff { if self.buff == nil { ret self.volAndPath[:self.volLen+self.w] } - ret self.volAndPath[:self.volLen] + unsafe::BytesStr(self.buff[:self.w]) + ret self.volAndPath[:self.volLen] + str(self.buff[:self.w]) } }