Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions crates/ts_goport/src/checker/checker_p28.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,7 @@ impl Checker {
}
if named_types_count + reduced_types.len() == type_set.len() {
for &t in &named_unions {
let (inserted, _) = self.insert_type(&reduced_types, t);
reduced_types = inserted;
self.insert_type_into(&mut reduced_types, t);
}
origin = self.new_union_type(ObjectFlags::NONE, &reduced_types);
}
Expand Down Expand Up @@ -1571,7 +1570,7 @@ impl Checker {
for &t in types.iter() {
if let Some((variable, primitive)) = self.constrained_type_variable_parts_p28(t) {
if variable == type_variable {
(primitives, _) = self.insert_type(&primitives, primitive);
self.insert_type_into(&mut primitives, primitive);
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions crates/ts_goport/src/checker/checker_p29.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@ impl Checker {
for &u in &union_types {
for i in 0..self.ty(u).types().len() {
let t = self.type_at(u, i);
let (new_checked, inserted) = self.insert_type(&checked, t);
checked = new_checked;
let inserted = self.insert_type_into(&mut checked, t);
if inserted {
if self.each_union_contains(&union_types, t) {
// undefinedType/missingType are always sorted first so we leverage that here
Expand All @@ -541,7 +540,7 @@ impl Checker {
result[0] = self.missing_type;
continue;
}
result = self.insert_type(&result, t).0;
self.insert_type_into(&mut result, t);
}
}
}
Expand Down Expand Up @@ -962,6 +961,16 @@ impl Checker {
}
}

/// Go `insertType` for an already owned buffer. Preserve the search and
/// its comparison effects, but retain capacity and copy nothing on a hit.
pub(crate) fn insert_type_into(&self, types: &mut Vec<TypeId>, t: TypeId) -> bool {
let (index, found) = self.search_union_types(types, t);
if !found {
types.insert(index, t);
}
!found
}

// Go: checker/checker.go:27093 countTypes
pub fn count_types(&self, t: TypeId) -> i32 {
let ty = self.ty(t);
Expand Down