Commit d5bd5185 authored by Istiaque Ahmed's avatar Istiaque Ahmed Committed by Commit Bot

[Ext] Cosmetic code: Remove escaping " and \ in generated_schemas

Use raw string literals instead to avoid hurting readers' eyes (note:
no one should read them though). For example, this CL turns
const char kUsb[] = "{\"functions\":[{\"parameters\":[{\"$ref\":...
to
const char kUsb[] = R"R({"functions":[{"parameters":[{"$ref":...
in gen/extensions/common/api/generated_schemas.cc

This makes generated .cc file size slightly smaller: e.g. in linux cros
build, the sizes in bytes are (before->after):
gen/chrome/../apps/platform_apps/../generated_schemas.cc 14137 -> 12396
gen/chrome/../extensions/../generated_schemas.cc        426698 -> 367237
gen/extensions/../generated_schemas.cc                  369079 -> 318170
gen/extensions/shell/../generated_schemas.cc              1632 -> 1535

Note that this should not have any impact on binary size.

Bug: None
Test: None, no visible changes expected.
Change-Id: I432c510396ead6e86fae71f63a3e2c099420b485
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2133658Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755987}
parent 4f1ba9f8
......@@ -340,17 +340,16 @@ class _SchemasCCGenerator(object):
json_content = json.dumps(_PrefixSchemaWithNamespace(
_RemoveUnneededFields(api)),
separators=(',', ':'))
# Escape all double-quotes and backslashes. For this to output a valid
# JSON C string, we need to escape \ and ". Note that some schemas are
# This will output a valid JSON C string. Note that some schemas are
# too large to compile on windows. Split the JSON up into several
# strings, since apparently that helps.
max_length = 8192
segments = [
json_content[i:i + max_length].replace('\\', '\\\\').replace(
'"', '\\"') for i in range(0, len(json_content), max_length)
json_content[i:i + max_length]
for i in range(0, len(json_content), max_length)
]
c.Append('const char %s[] = "%s";' %
(_FormatNameAsConstant(namespace.name), '" "'.join(segments)))
c.Append('const char %s[] = R"R(%s)R";' % (_FormatNameAsConstant(
namespace.name), ')R" R"R('.join(segments)))
c.Append('} // namespace')
c.Append()
c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment