From d520db53558e3666e0bf59ff1a29588e5aa65756 Mon Sep 17 00:00:00 2001 From: Donald Chai Date: Mon, 25 Nov 2019 23:05:51 -0800 Subject: Factor out repeated shift instructions to reduce code size R8 has some O(n^3) analysis somewhere, so this should speed up analysis of "onResourcesLoaded" by 1.5^3=3.3x. Bug: 145052564 Change-Id: Ib6ab111511d6bd3afae0c29cd00f743e7128768a Tested: aapt2_tests --- tools/aapt2/java/JavaClassGenerator.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tools/aapt2/java/JavaClassGenerator.cpp') diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp index 31d205e1b9c9..6c3bcf039be1 100644 --- a/tools/aapt2/java/JavaClassGenerator.cpp +++ b/tools/aapt2/java/JavaClassGenerator.cpp @@ -428,7 +428,7 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res out_rewrite_method->AppendStatement( StringPrintf(" if ((styleable.%s[i] & 0xff000000) == 0) {", array_field_name.data())); out_rewrite_method->AppendStatement( - StringPrintf(" styleable.%s[i] = (styleable.%s[i] & 0x00ffffff) | (p << 24);", + StringPrintf(" styleable.%s[i] = (styleable.%s[i] & 0x00ffffff) | packageIdBits;", array_field_name.data(), array_field_name.data())); out_rewrite_method->AppendStatement(" }"); out_rewrite_method->AppendStatement("}"); @@ -487,9 +487,9 @@ void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const Reso if (out_rewrite_method != nullptr) { const StringPiece& type_str = to_string(name.type); - out_rewrite_method->AppendStatement(StringPrintf("%s.%s = (%s.%s & 0x00ffffff) | (p << 24);", - type_str.data(), field_name.data(), - type_str.data(), field_name.data())); + out_rewrite_method->AppendStatement( + StringPrintf("%s.%s = (%s.%s & 0x00ffffff) | packageIdBits;", type_str.data(), + field_name.data(), type_str.data(), field_name.data())); } } @@ -599,6 +599,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, rewrite_method->AppendStatement( StringPrintf("%s.R.onResourcesLoaded(p);", package_to_callback.data())); } + rewrite_method->AppendStatement("final int packageIdBits = p << 24;"); } for (const auto& package : table_->packages) { -- cgit v1.2.3 From 4e19c48a6e741c96956240e96046d5baaa77be3d Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Fri, 6 Dec 2019 12:20:21 -0800 Subject: Fix aapt2 JavaClassGenerator Maybe#value() call before check Previous refactor accidentally assumed all attributes would have resolvable symbols when generating the R class. Restore previous behavior of calling SkipSymbol before retrieving the attribute comment. Bug: 145685954 Test: m TeleService Change-Id: Ie8e1092556bc0b6a764462ffa0b99a876bcbd70e --- tools/aapt2/java/JavaClassGenerator.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tools/aapt2/java/JavaClassGenerator.cpp') diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp index 31d205e1b9c9..5b90d8d31db7 100644 --- a/tools/aapt2/java/JavaClassGenerator.cpp +++ b/tools/aapt2/java/JavaClassGenerator.cpp @@ -304,9 +304,11 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res auto documentation_remove_iter = std::remove_if(documentation_attrs.begin(), documentation_attrs.end(), [&](StyleableAttr entry) -> bool { - StringPiece attr_comment_line = entry.symbol.value().attribute->GetComment(); - return SkipSymbol(entry.symbol) || attr_comment_line.contains("@removed") - || attr_comment_line.contains("@hide"); + if (SkipSymbol(entry.symbol)) { + return true; + } + const StringPiece attr_comment_line = entry.symbol.value().attribute->GetComment(); + return attr_comment_line.contains("@removed") || attr_comment_line.contains("@hide"); }); documentation_attrs.erase(documentation_remove_iter, documentation_attrs.end()); -- cgit v1.2.3 From de6e6f2098042bb91f7dac965d2b047c74c920f2 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Mon, 22 Jun 2020 10:17:02 -0700 Subject: Don't add API annotations in the internal R.java I'm trying to enable a check for the following structure: ``` /** @hide */ public class Class1 { /** @hide */ @SystemApi // Invalid because the class is hidden. public void method1() { } } ``` The internal R.java file violates this, which this change is going to fix. Bug: 159162473 Test: build (treehugger) Test: atest aapt2_tests Change-Id: I613e8611ddaf5f8e4761d351d4cd0142d59c7cc9 --- tools/aapt2/java/JavaClassGenerator.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tools/aapt2/java/JavaClassGenerator.cpp') diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp index bb541fe2490b..dffad3b99c06 100644 --- a/tools/aapt2/java/JavaClassGenerator.cpp +++ b/tools/aapt2/java/JavaClassGenerator.cpp @@ -604,6 +604,8 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, rewrite_method->AppendStatement("final int packageIdBits = p << 24;"); } + const bool is_public = (options_.types == JavaClassGeneratorOptions::SymbolTypes::kPublic); + for (const auto& package : table_->packages) { for (const auto& type : package->types) { if (type->type == ResourceType::kAttrPrivate) { @@ -612,8 +614,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, } // Stay consistent with AAPT and generate an empty type class if the R class is public. - const bool force_creation_if_empty = - (options_.types == JavaClassGeneratorOptions::SymbolTypes::kPublic); + const bool force_creation_if_empty = is_public; std::unique_ptr class_def; if (out != nullptr) { @@ -637,8 +638,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, } } - if (out != nullptr && type->type == ResourceType::kStyleable && - options_.types == JavaClassGeneratorOptions::SymbolTypes::kPublic) { + if (out != nullptr && type->type == ResourceType::kStyleable && is_public) { // When generating a public R class, we don't want Styleable to be part // of the API. It is only emitted for documentation purposes. class_def->GetCommentBuilder()->AppendComment("@doconly"); @@ -657,7 +657,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, if (out != nullptr) { AppendJavaDocAnnotations(options_.javadoc_annotations, r_class.GetCommentBuilder()); - ClassDefinition::WriteJavaFile(&r_class, out_package_name, options_.use_final, out); + ClassDefinition::WriteJavaFile(&r_class, out_package_name, options_.use_final, !is_public, out); } return true; } -- cgit v1.2.3