Skip to content

Commit

Permalink
compiler: take advantage of the new --opt-str optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Oct 23, 2024
1 parent 892fc5b commit 1b54518
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 64 deletions.
5 changes: 2 additions & 3 deletions src/julec/obj/cxx/object.jule
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()]
Expand Down
4 changes: 1 addition & 3 deletions std/bytes/bytes.jule
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 0 additions & 24 deletions std/internal/fastbytes/fastbytes.jule
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 0 additions & 29 deletions std/internal/fastbytes/fastbytes_test.jule
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions std/net/ip.jule
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions std/os/filepath/path.jule
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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])
}
}

Expand Down

0 comments on commit 1b54518

Please sign in to comment.