Skip to content

Commit

Permalink
Move const PortName data out of header file
Browse files Browse the repository at this point in the history
When non-integral const data is defined in a header file it often ends
up being instantiated in multiple translation units. It also ends up in
the read/write data segment which means it isn't shared between
processes. This change has the following affect on the size of sections
in a 32-bit release Windows build:

chrome.dll
     .text:   144 bytes change
    .rdata:   -32 bytes change
     .data:  -736 bytes change
    .reloc:   140 bytes change
Total change:  -484 bytes

chrome_child.dll
     .text:    32 bytes change
    .rdata:  -112 bytes change
     .data:  -736 bytes change
    .reloc:   -84 bytes change
Total change:  -900 bytes

Note that the sections that increase in size are either shareable
(.text) or discardable (.reloc).

I wish I could use "extern constexpr" to ensure that no constructors are
run, but C++ does not allow that. inline constexpr is not yet supported,
and making the variables a static constexpr member of a class (see
crrev.com/2512753002) seems like overkill and doesn't seem to help.

BUG=630755

Review-Url: https://codereview.chromium.org/2515483002
Cr-Commit-Position: refs/heads/master@{#433727}
  • Loading branch information
randomascii authored and Commit bot committed Nov 22, 2016
1 parent f7ef004 commit facf441
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions mojo/edk/system/ports/name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace mojo {
namespace edk {
namespace ports {

extern const PortName kInvalidPortName = {0, 0};

extern const NodeName kInvalidNodeName = {0, 0};

std::ostream& operator<<(std::ostream& stream, const Name& name) {
std::ios::fmtflags flags(stream.flags());
stream << std::hex << std::uppercase << name.v1;
Expand Down
4 changes: 2 additions & 2 deletions mojo/edk/system/ports/name.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ struct PortName : Name {
PortName(uint64_t v1, uint64_t v2) : Name(v1, v2) {}
};

const PortName kInvalidPortName = {0, 0};
extern const PortName kInvalidPortName;

struct NodeName : Name {
NodeName() : Name(0, 0) {}
NodeName(uint64_t v1, uint64_t v2) : Name(v1, v2) {}
};

const NodeName kInvalidNodeName = {0, 0};
extern const NodeName kInvalidNodeName;

} // namespace ports
} // namespace edk
Expand Down

0 comments on commit facf441

Please sign in to comment.