UninitializedMemoryHacks
authorNathan Bronson <ngbronson@fb.com>
Tue, 6 Jun 2017 16:08:51 +0000 (09:08 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 6 Jun 2017 16:20:43 +0000 (09:20 -0700)
commit7cf58370d0f79c92b324413797f2239653f5d2c2
tree93e5f5da9b337befe68b817d5654787e8bcf7134
parentcd201c86411f960e6e63c8222a334cea5ed67768
UninitializedMemoryHacks

Summary:
This diff adds helper functions that can resize std::string or std::vector
without constructing or initializing new elements.  They are designed
for retroactively optimizing code where touching every element twice
(or touching never-used elements once) shows up in profiling, and where
restructuring the code to use fixed-length arrays or IOBuf-s would
be difficult.

Implementations are provided for 5 string implementations (pre-c++11
libstdc++, libstdc++ with SSO, libc++, std::basic_fbstring, and MSVC)
and 3 vector implementations (libstdc++, libc++, and MSVC).  On an
unsupported platform you will hopefully get a #warn if you include
UninitializedMemoryHacks.h followed by a linker error if you actually
use it.

Reviewed By: yfeldblum

Differential Revision: D5102679

fbshipit-source-id: 536c00eabae4cdb8a0affe3e919a372f4dc51ac5
folly/Makefile.am
folly/memory/UninitializedMemoryHacks.h [new file with mode: 0644]
folly/memory/test/UninitializedMemoryHacksODR.cpp [new file with mode: 0644]
folly/memory/test/UninitializedMemoryHacksTest.cpp [new file with mode: 0644]