removing string optimizations

This commit is contained in:
mlokr 2024-07-07 12:15:48 +02:00
parent cdc8cb35f7
commit 12c7467be2
No known key found for this signature in database
GPG key ID: DEA147DDEE644993
2 changed files with 34 additions and 28 deletions

View file

@ -421,8 +421,9 @@ main := fn(): int {
y: 2, y: 2,
}, },
}; };
if *(&pixel.point.x + 1) != 2 { soupan := 1;
if *(&pixel.point.x + soupan) != 2 {
return 0; return 0;
} }

View file

@ -264,6 +264,10 @@ pub mod ty {
(U8..=UINT).contains(&self.repr()) (U8..=UINT).contains(&self.repr())
} }
pub fn is_integer(self) -> bool {
(U8..=INT).contains(&self.repr())
}
pub fn strip_pointer(self) -> Self { pub fn strip_pointer(self) -> Self {
match self.expand() { match self.expand() {
Kind::Ptr(_) => Kind::Builtin(UINT).compress(), Kind::Ptr(_) => Kind::Builtin(UINT).compress(),
@ -282,6 +286,7 @@ pub mod ty {
_ if oa == ob => oa, _ if oa == ob => oa,
_ if a.is_signed() && b.is_signed() || a.is_unsigned() && b.is_unsigned() => ob, _ if a.is_signed() && b.is_signed() || a.is_unsigned() && b.is_unsigned() => ob,
_ if a.is_unsigned() && b.is_signed() && a.repr() - U8 < b.repr() - I8 => ob, _ if a.is_unsigned() && b.is_signed() && a.repr() - U8 < b.repr() - I8 => ob,
_ if oa.is_integer() && ob.is_pointer() => ob,
_ => return None, _ => return None,
}) })
} }
@ -2624,7 +2629,7 @@ impl Codegen {
true true
}); });
self.compress_strings(); //self.compress_strings();
let base = self.output.code.len() as u32; let base = self.output.code.len() as u32;
self.output.code.append(&mut self.string_data); self.output.code.append(&mut self.string_data);
@ -2634,34 +2639,34 @@ impl Codegen {
} }
} }
fn compress_strings(&mut self) { //fn compress_strings(&mut self) {
// FIXME: we can go faster // // FIXME: we can go faster
self.output // self.output
.strings // .strings
.sort_by(|a, b| self.string_data[b.range()].cmp(&self.string_data[a.range()])); // .sort_by(|a, b| self.string_data[b.range()].cmp(&self.string_data[a.range()]));
let mut cursor = 0; // let mut cursor = 0;
let mut anchor = 0; // let mut anchor = 0;
for i in 1..self.output.strings.len() { // for i in 1..self.output.strings.len() {
let [a, b] = self.output.strings.get_many_mut([anchor, i]).unwrap(); // let [a, b] = self.output.strings.get_many_mut([anchor, i]).unwrap();
if self.string_data[a.range()].ends_with(&self.string_data[b.range()]) { // if self.string_data[a.range()].ends_with(&self.string_data[b.range()]) {
b.range.end = a.range.end; // b.range.end = a.range.end;
b.range.start = a.range.end - (b.range.end - b.range.start); // b.range.start = a.range.end - (b.range.end - b.range.start);
} else { // } else {
self.string_data.copy_within(a.range(), cursor); // self.string_data.copy_within(a.range(), cursor);
cursor += a.range.len(); // cursor += a.range.len();
anchor = i; // anchor = i;
} // }
} // }
if !self.output.strings.is_empty() { // if !self.output.strings.is_empty() {
let a = &self.output.strings[anchor]; // let a = &self.output.strings[anchor];
self.string_data.copy_within(a.range(), cursor); // self.string_data.copy_within(a.range(), cursor);
cursor += a.range.len(); // cursor += a.range.len();
} // }
self.string_data.truncate(cursor) // self.string_data.truncate(cursor)
} //}
// TODO: sometimes its better to do this in bulk // TODO: sometimes its better to do this in bulk
fn ty(&mut self, expr: &Expr) -> ty::Id { fn ty(&mut self, expr: &Expr) -> ty::Id {