Skip to content

Commit 0e24c9a

Browse files
committed
Next revision of optimizing get_declaration_of
Motivated by improving #904 Fixes bugs - initial version wasn't well tested, this one has been validated to run through regression tests with the same internal results as the old unoptimized function A second optimization is currently commented out until I finish regression-testing it too
1 parent 6a2a809 commit 0e24c9a

File tree

4 files changed

+337
-51
lines changed

4 files changed

+337
-51
lines changed

Diff for: source/common.h

+21-19
Original file line numberDiff line numberDiff line change
@@ -1004,12 +1004,12 @@ class stable_vector
10041004
}
10051005

10061006
auto operator[](size_t idx) -> T& {
1007-
testing.enforce(idx < size());
1007+
bounds_safety.enforce(idx < size());
10081008
return data[idx / PageSize][idx % PageSize];
10091009
}
10101010

10111011
auto operator[](size_t idx) const -> T const& {
1012-
testing.enforce(idx < size());
1012+
bounds_safety.enforce(idx < size());
10131013
return data[idx / PageSize][idx % PageSize];
10141014
}
10151015

@@ -1042,14 +1042,16 @@ class stable_vector
10421042
//-------------------------------------------------------------------
10431043
// Debug interface
10441044
//
1045-
auto debug_print() -> void {
1046-
std::cout << "stable_vector:\n";
1045+
auto debug_print(std::ostream& o) const
1046+
-> void
1047+
{
1048+
o << "stable_vector:\n";
10471049
for (auto i = 0; auto& chunk : data) {
1048-
std::cout << " -- page " << i++ << " --\n ";
1050+
o << " -- page " << i++ << " --\n ";
10491051
for (auto e : chunk) {
1050-
std::cout << e << ' ';
1052+
o << e << ' ';
10511053
}
1052-
std::cout << "\n";
1054+
o << "\n";
10531055
}
10541056
}
10551057

@@ -1067,12 +1069,12 @@ class stable_vector
10671069
using iterator_category = std::random_access_iterator_tag;
10681070

10691071
iterator( stable_vector* v_ = nullptr, size_t pos_ = 0) : v{v_}, pos{pos_} { }
1070-
auto operator++ () -> void { if (pos < v->size()) { ++pos; } }
1071-
auto operator-- () -> void { if (pos > 0 ) { --pos; } }
1072-
auto operator+= (size_t off) -> void { if (pos + off < v->size()) { pos += off; } else { pos = v->size(); } }
1073-
auto operator-= (size_t off) -> void { if (pos - off > 0 ) { pos -= off; } else { pos = 0; } }
1074-
auto operator* () -> T& { return (*v)[pos ]; }
1075-
auto operator-> () -> T* { return &(*v)[pos ]; }
1072+
auto operator++ () -> iterator { if (pos < v->size()) { ++pos; } return *this; }
1073+
auto operator-- () -> iterator { if (pos > 0 ) { --pos; } return *this; }
1074+
auto operator+= (size_t off) -> iterator { if (pos + off < v->size()) { pos += off; } else { pos = v->size(); } return *this; }
1075+
auto operator-= (size_t off) -> iterator { if (pos - off > 0 ) { pos -= off; } else { pos = 0; } return *this; }
1076+
auto operator* () const -> T& { return (*v)[pos ]; }
1077+
auto operator-> () const -> T* { return &(*v)[pos ]; }
10761078
auto operator[] (size_t off) -> T& { return (*v)[pos + off]; }
10771079
auto operator+ (size_t off) -> iterator { auto i = *this; i += off; return i; }
10781080
auto operator- (size_t off) -> iterator { auto i = *this; i -= off; return i; }
@@ -1091,12 +1093,12 @@ class stable_vector
10911093
using iterator_category = std::random_access_iterator_tag;
10921094

10931095
const_iterator( stable_vector const* v_ = nullptr, size_t pos_ = 0) : v{v_}, pos{pos_} { }
1094-
auto operator++ () -> void { if (pos < v->size()) { ++pos; } }
1095-
auto operator-- () -> void { if (pos > 0 ) { --pos; } }
1096-
auto operator+= (size_t off) -> void { if (pos + off < v->size()) { pos += off; } else { pos = v->size(); } }
1097-
auto operator-= (size_t off) -> void { if (pos - off > 0 ) { pos -= off; } else { pos = 0; } }
1098-
auto operator* () -> T const& { return (*v)[pos ]; }
1099-
auto operator-> () -> T const* { return &(*v)[pos ]; }
1096+
auto operator++ () -> const_iterator { if (pos < v->size()) { ++pos; } return *this; }
1097+
auto operator-- () -> const_iterator { if (pos > 0 ) { --pos; } return *this; }
1098+
auto operator+= (size_t off) -> const_iterator { if (pos + off < v->size()) { pos += off; } else { pos = v->size(); } return *this; }
1099+
auto operator-= (size_t off) -> const_iterator { if (pos - off > 0 ) { pos -= off; } else { pos = 0; } return *this; }
1100+
auto operator* () const -> T const& { return (*v)[pos ]; }
1101+
auto operator-> () const -> T const* { return &(*v)[pos ]; }
11001102
auto operator[] (size_t off) -> T const& { return (*v)[pos + off]; }
11011103
auto operator+ (size_t off) -> const_iterator { auto i = *this; i += off; return i; }
11021104
auto operator- (size_t off) -> const_iterator { auto i = *this; i -= off; return i; }

Diff for: source/parse.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -5534,7 +5534,7 @@ class parser
55345534
//-----------------------------------------------------------------------
55355535
// visit
55365536
//
5537-
auto visit(auto& v) -> void
5537+
auto visit(auto& v) const -> void
55385538
{
55395539
parse_tree->visit(v, 0);
55405540
}
@@ -9098,7 +9098,7 @@ class parser
90989098
//-----------------------------------------------------------------------
90999099
// debug_print
91009100
//
9101-
auto debug_print(std::ostream& o)
9101+
auto debug_print(std::ostream& o) const
91029102
-> void;
91039103
};
91049104

@@ -9406,7 +9406,7 @@ class parse_tree_printer : printing_visitor
94069406
};
94079407

94089408

9409-
auto parser::debug_print(std::ostream& o)
9409+
auto parser::debug_print(std::ostream& o) const
94109410

94119411
-> void
94129412
{

0 commit comments

Comments
 (0)