[goalc] reduce compiler memory usage (#2247)

This commit is contained in:
water111
2023-02-24 18:32:30 -05:00
committed by GitHub
parent e10ca97891
commit e2b7e5c001
25 changed files with 206 additions and 159 deletions
+42 -31
View File
@@ -175,39 +175,45 @@ std::optional<TextDb::ShortInfo> TextDb::get_short_info_for(const std::shared_pt
return std::make_optional(info_result);
}
std::optional<TextDb::ShortInfo> TextDb::try_get_short_info(
const std::shared_ptr<goos::HeapObject>& heap_obj) const {
auto it = m_map.find(heap_obj);
if (it != m_map.end()) {
auto& frag = it->second.frag;
// shorten the string
std::string name = frag->get_description();
size_t start = 0;
for (size_t i = 0; i < name.size(); i++) {
if (name[i] == '/' || name[i] == '\\') {
start = i + 1;
}
}
if (start < name.size()) {
name = name.substr(start);
}
ShortInfo result;
result.filename = name;
int line_idx = frag->get_line_idx(it->second.offset);
result.line_idx_to_display = line_idx + 1;
int offset_of_line = frag->get_offset_of_line(line_idx);
int offset_of_next_line = frag->get_offset_of_line(line_idx + 1);
int line_length = offset_of_next_line - offset_of_line;
int start_offset_in_line = it->second.offset - offset_of_line - 1;
result.pos_in_line = std::max(start_offset_in_line, 0);
result.line_text = std::string(frag->get_text() + offset_of_line + 1, line_length - 1);
return result;
}
return {};
}
std::optional<TextDb::ShortInfo> TextDb::try_get_short_info(const Object& o) const {
if (o.is_pair()) {
auto it = m_map.find(o.heap_obj);
if (it != m_map.end()) {
auto& frag = it->second.frag;
// shorten the string
std::string name = frag->get_description();
size_t start = 0;
for (size_t i = 0; i < name.size(); i++) {
if (name[i] == '/' || name[i] == '\\') {
start = i + 1;
}
}
if (start < name.size()) {
name = name.substr(start);
}
ShortInfo result;
result.filename = name;
int line_idx = frag->get_line_idx(it->second.offset);
result.line_idx_to_display = line_idx + 1;
int offset_of_line = frag->get_offset_of_line(line_idx);
int offset_of_next_line = frag->get_offset_of_line(line_idx + 1);
int line_length = offset_of_next_line - offset_of_line;
int start_offset_in_line = it->second.offset - offset_of_line - 1;
result.pos_in_line = std::max(start_offset_in_line, 0);
result.line_text = std::string(frag->get_text() + offset_of_line + 1, line_length - 1);
return result;
}
return try_get_short_info(o.heap_obj);
}
return {};
@@ -245,4 +251,9 @@ void TextDb::inherit_info(const Object& parent, const Object& child) {
}
}
}
void TextDb::clear_info() {
m_map.clear();
m_fragments.clear();
}
} // namespace goos