Commit 26816320 authored by brucedawson's avatar brucedawson Committed by Commit bot

Optimize GetPathForVectorIcon*, save ~290 KB on disk

VC++ was initializing all of the static PathElement arrays in
GetPathForVectorIcon and GetPathForVectorIconAt1xScale at runtime, which
meant that these were the largest and sixth largest functions in
chrome.dll, and similarly in chrome_child.dll. Tagging the arrays and
types as constexpr shrinks these functions down to nothing, saves about
~50 KB of per-process private data, and actually helps them compile
slightly faster.

The approximate section size changes are:
       .text: -164224 bytes change
      .rdata:   51984 bytes change
       .data:  -54976 bytes change
      .reloc:  -23204 bytes change

These gains apply both to chrome.dll and chrome_child.dll.

BUG=679539

Review-Url: https://codereview.chromium.org/2620653004
Cr-Commit-Position: refs/heads/master@{#442751}
parent f8bee1d4
......@@ -11,7 +11,7 @@
#include "ui/gfx/vector_icon_types.h"
#define PATH_ELEMENT_TEMPLATE(path_name, ...) \
static gfx::PathElement path_name[] = {__VA_ARGS__};
static constexpr gfx::PathElement path_name[] = {__VA_ARGS__};
#define VECTOR_ICON_TEMPLATE(icon_name, path_name, path_name_1x) \
const gfx::VectorIcon icon_name = { path_name , path_name_1x };
......
......@@ -11,7 +11,7 @@
#include "ui/gfx/vector_icon_types.h"
#define PATH_ELEMENT_TEMPLATE(path_name, ...) \
static gfx::PathElement path_name[] = {__VA_ARGS__};
static constexpr gfx::PathElement path_name[] = {__VA_ARGS__};
#define VECTOR_ICON_TEMPLATE(icon_name, path_name, path_name_1x) \
const gfx::VectorIcon icon_name = { path_name , path_name_1x };
......
......@@ -12,19 +12,12 @@
#define ICON_TEMPLATE(icon_name, ...) \
case VectorIconId::icon_name: {\
static PathElement path[] = {__VA_ARGS__};\
static constexpr PathElement path[] = {__VA_ARGS__};\
return path;\
}
namespace gfx {
#if defined(OS_WIN)
#pragma warning(push)
// Disable "function size suppresses optimizations" warning.
#pragma warning(disable: 4883)
#endif // defined(OS_WIN)
const PathElement* GetPathForVectorIcon(VectorIconId id) {
switch (id) {
TEMPLATE_PLACEHOLDER
......@@ -47,8 +40,4 @@ TEMPLATE_PLACEHOLDER_1X
}
}
#if defined(OS_WIN)
#pragma warning(pop)
#endif // defined(OS_WIN)
} // namespace gfx
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