Skip to content

Commit 130f149

Browse files
committed
Clean up declaration_starts optimization a bit
Build declaration_starts as we go, instead of rebuilding it in pieces later - I may get rid of it entirely later in favor of a better optimization I'm thinking about, but at least now while we have it this is a cleaner way to build it Also make global_token_counter a sema member - part of getting rid of static variables so that compiling more than one file on the same cppfront command line starts fresh each time (there are a few more statics to go)
1 parent da32b4f commit 130f149

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

source/sema.h

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ class sema
393393
public:
394394
std::vector<error_entry>& errors;
395395
stable_vector<symbol> symbols;
396+
index_t global_token_counter = 1;
396397

397398
std::vector<selection_statement_node const*> active_selections;
398399

@@ -567,12 +568,12 @@ class sema
567568
++i;
568569
}
569570

571+
initial_find_old = i;
572+
570573
if (i == symbols.cbegin()) {
571574
return nullptr;
572575
}
573576

574-
initial_find_old = i;
575-
576577
auto depth = 0;
577578

578579
// If we found it exactly, we have its depth
@@ -754,35 +755,23 @@ class sema
754755

755756
// First find the position the query is coming from
756757
// and remember its depth
757-
auto i = symbols.cbegin();
758-
auto depth = 0;
759-
760-
{
761-
CPP2_SCOPE_TIMER("get_declaration_of_new - phase 1 initial loop");
762-
763-
// If the declaration_starts list got this far yet, use that to
764-
// skip repeating the whole linear search from the table beginning
765-
//
766758
auto probe = std::lower_bound(
767759
declaration_starts.begin(),
768760
declaration_starts.end(),
769761
t.get_global_token_order()
770762
);
771-
if (probe != declaration_starts.end())
763+
if (
764+
probe != declaration_starts.end()
765+
&& probe->token_order > t.get_global_token_order()
766+
)
772767
{
773-
if (probe->iter->get_global_token_order() != t.get_global_token_order()) {
774-
--probe;
775-
}
776-
i = probe->iter;
768+
--probe;
777769
}
770+
auto i = probe != declaration_starts.end() ? probe->iter : declaration_starts.back().iter;
771+
auto depth = 0;
778772

779-
// Else resume appending values to the declaration_starts list
780-
//
781-
else
782773
{
783-
// Start right after where we left off
784-
i = declaration_starts.back().iter;
785-
}
774+
CPP2_SCOPE_TIMER("get_declaration_of_new - phase 1 initial loop");
786775

787776
while (
788777
i != symbols.cend()
@@ -805,12 +794,12 @@ class sema
805794
++i;
806795
}
807796

797+
initial_find_new = i;
798+
808799
if (i == symbols.cbegin()) {
809800
return nullptr;
810801
}
811802

812-
initial_find_new = i;
813-
814803
// If we found it exactly, we have its depth
815804
if (
816805
i != symbols.cend()
@@ -2789,6 +2778,7 @@ class sema
27892778

27902779
if (n.pass != passing_style::out) {
27912780
push_activation( declaration_sym( true, n.declaration.get(), n.declaration->name(), n.declaration->initializer.get(), &n, inside_returns_list));
2781+
declaration_starts.emplace_back( global_token_counter, symbols.cend()-1 );
27922782
}
27932783
}
27942784

@@ -2864,6 +2854,13 @@ class sema
28642854
)
28652855
{
28662856
push_activation( declaration_sym( true, &n, n.name(), n.initializer.get(), inside_out_parameter, false, inside_returns_list ) );
2857+
if (
2858+
n.has_name()
2859+
&& !n.has_name("_")
2860+
)
2861+
{
2862+
declaration_starts.emplace_back( global_token_counter, symbols.cend()-1 );
2863+
}
28672864
if (!n.is_object()) {
28682865
++scope_depth;
28692866
}
@@ -2961,7 +2958,6 @@ class sema
29612958

29622959
// By giving tokens an order during sema
29632960
// generated code can be equally checked
2964-
static index_t global_token_counter = 1; // TODO static
29652961
t.set_global_token_order( global_token_counter++ );
29662962

29672963
auto started_member_access =

0 commit comments

Comments
 (0)