Merge pull request #8006 from haberman/php-internaladd
[PHP] Optimized away hex2bin() call in generated code
This commit is contained in:
commit
ea513d71e0
@ -1010,16 +1010,28 @@ void GenerateAddFileToPool(const FileDescriptor* file, const Options& options,
|
|||||||
std::string files_data;
|
std::string files_data;
|
||||||
files.SerializeToString(&files_data);
|
files.SerializeToString(&files_data);
|
||||||
|
|
||||||
printer->Print("$pool->internalAddGeneratedFile(hex2bin(\n");
|
printer->Print("$pool->internalAddGeneratedFile(\n");
|
||||||
Indent(printer);
|
Indent(printer);
|
||||||
|
printer->Print("'");
|
||||||
|
|
||||||
printer->Print(
|
for (auto ch : files_data) {
|
||||||
"\"^data^\"\n",
|
switch (ch) {
|
||||||
"data", BinaryToHex(files_data));
|
case '\\':
|
||||||
|
printer->Print(R"(\\)");
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
printer->Print(R"(\')");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printer->Print("^char^", "char", std::string(1, ch));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printer->Print("'\n");
|
||||||
Outdent(printer);
|
Outdent(printer);
|
||||||
printer->Print(
|
printer->Print(
|
||||||
"), true);\n\n");
|
", true);\n\n");
|
||||||
}
|
}
|
||||||
printer->Print(
|
printer->Print(
|
||||||
"static::$is_initialized = true;\n");
|
"static::$is_initialized = true;\n");
|
||||||
@ -1145,16 +1157,28 @@ void GenerateAddFilesToPool(const FileDescriptor* file, const Options& options,
|
|||||||
std::string files_data;
|
std::string files_data;
|
||||||
sorted_file_set.SerializeToString(&files_data);
|
sorted_file_set.SerializeToString(&files_data);
|
||||||
|
|
||||||
printer->Print("$pool->internalAddGeneratedFile(hex2bin(\n");
|
printer->Print("$pool->internalAddGeneratedFile(\n");
|
||||||
Indent(printer);
|
Indent(printer);
|
||||||
|
printer->Print("'");
|
||||||
|
|
||||||
printer->Print(
|
for (auto ch : files_data) {
|
||||||
"\"^data^\"\n",
|
switch (ch) {
|
||||||
"data", BinaryToHex(files_data));
|
case '\\':
|
||||||
|
printer->Print(R"(\\)");
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
printer->Print(R"(\')");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printer->Print("^char^", "char", std::string(1, ch));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printer->Print("'\n");
|
||||||
Outdent(printer);
|
Outdent(printer);
|
||||||
printer->Print(
|
printer->Print(
|
||||||
"), true);\n");
|
", true);\n");
|
||||||
|
|
||||||
printer->Print(
|
printer->Print(
|
||||||
"static::$is_initialized = true;\n");
|
"static::$is_initialized = true;\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user