C++: Optimize cc_shared_library

1. Don't pop from the front of the list being iterated on
2. Don't visit the same node_label more than once

RELNOTES:none
PiperOrigin-RevId: 307610981
Change-Id: I9b35a27a1bdabafbe290d1ff23eeb4659b07d554
This commit is contained in:
Googler 2020-04-21 08:37:54 -07:00 committed by Copybara-Service
parent 77099ee80d
commit a74452e910
1 changed files with 13 additions and 5 deletions

View File

@ -55,18 +55,26 @@ def _separate_static_and_dynamic_link_libraries(
link_statically_labels = {}
link_dynamically_labels = {}
# Horrible I know. Perhaps Starlark team gives me a way to prune a tree.
for i in range(1, 2147483647):
if len(all_children) == 0:
break
node = all_children.pop(0)
seen_labels = {}
# Horrible I know. Perhaps Starlark team gives me a way to prune a tree.
for i in range(2147483647):
if i == len(all_children):
break
node = all_children[i]
node_label = str(node.label)
if node_label in seen_labels:
continue
seen_labels[node_label] = True
if node_label in can_be_linked_dynamically:
link_dynamically_labels[node_label] = True
elif node_label not in preloaded_deps_direct_labels:
link_statically_labels[node_label] = node.linkable_more_than_once
all_children.extend(node.children)
return (link_statically_labels, link_dynamically_labels)
def _create_linker_context(ctx, linker_inputs):