Skip to content

Commit

Permalink
perf: do not check JsInfo hasattr for always-set attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Jun 10, 2024
1 parent 7a88898 commit 6c9002c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions js/private/js_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def gather_transitive_sources(sources, targets):
transitive = [
target[JsInfo].transitive_sources
for target in targets
if JsInfo in target and hasattr(target[JsInfo], "transitive_sources")
if JsInfo in target
]
return depset([], transitive = [sources] + transitive)

Expand All @@ -38,7 +38,7 @@ def gather_transitive_types(types, targets):
transitive = [
target[JsInfo].transitive_types
for target in targets
if JsInfo in target and hasattr(target[JsInfo], "transitive_types")
if JsInfo in target
]
return depset([], transitive = [types] + transitive)

Expand All @@ -56,7 +56,7 @@ def gather_npm_sources(srcs, deps):
return depset([], transitive = [
target[JsInfo].npm_sources
for target in srcs + deps
if JsInfo in target and hasattr(target[JsInfo], "npm_sources")
if JsInfo in target
])

def gather_npm_package_store_infos(targets):
Expand Down Expand Up @@ -275,15 +275,15 @@ def gather_files_from_js_infos(
for target in targets:
if JsInfo in target:
js_info = target[JsInfo]
if include_sources and hasattr(js_info, "sources"):
if include_sources:
files_depsets.append(js_info.sources)
if include_types and hasattr(js_info, "types"):
if include_types:
files_depsets.append(js_info.types)
if include_transitive_sources and hasattr(js_info, "transitive_sources"):
if include_transitive_sources:
files_depsets.append(js_info.transitive_sources)
if include_transitive_types and hasattr(js_info, "transitive_types"):
if include_transitive_types:
files_depsets.append(js_info.transitive_types)
if include_npm_sources and hasattr(js_info, "npm_sources"):
if include_npm_sources:
files_depsets.append(js_info.npm_sources)

return depset([], transitive = files_depsets)
4 changes: 2 additions & 2 deletions js/private/js_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ def _gather_sources_and_types(ctx, targets, files):
sources = depset(sources, transitive = [
target[JsInfo].sources
for target in targets
if JsInfo in target and hasattr(target[JsInfo], "sources")
if JsInfo in target
])

# types as depset
types = depset(types, transitive = [
target[JsInfo].types
for target in targets
if JsInfo in target and hasattr(target[JsInfo], "types")
if JsInfo in target
])

return (sources, types)
Expand Down
2 changes: 1 addition & 1 deletion npm/private/npm_package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _npm_package_impl(ctx):
npm_package_store_infos = [
target[JsInfo].npm_package_store_infos
for target in ctx.attr.srcs
if JsInfo in target and hasattr(target[JsInfo], "npm_package_store_infos")
if JsInfo in target
]
npm_package_store_infos.append(js_lib_helpers.gather_npm_package_store_infos(
targets = ctx.attr.data,
Expand Down

0 comments on commit 6c9002c

Please sign in to comment.