Commit 8d4e8ede authored by Giuseppe Ottaviano's avatar Giuseppe Ottaviano Committed by Facebook GitHub Bot

Specialize F14Table default constructor to avoid reserve() instantiation

Summary: F14 class member fields are often in headers, and often the default constructor is implicit. The current implementation unconditionally instantiates `reserve()`, which has non-negligible cost. By specializing the default constructor we can avoid that in the common case.

Reviewed By: philippv, luciang

Differential Revision: D22027490

fbshipit-source-id: 964d9fa19ca92797bcb209e09959dc4706af39d4
parent 248b90f6
...@@ -105,8 +105,7 @@ class F14BasicMap { ...@@ -105,8 +105,7 @@ class F14BasicMap {
public: public:
//// PUBLIC - Member functions //// PUBLIC - Member functions
F14BasicMap() noexcept(Policy::kDefaultConstructIsNoexcept) F14BasicMap() noexcept(Policy::kDefaultConstructIsNoexcept) : table_{} {}
: F14BasicMap(0) {}
explicit F14BasicMap( explicit F14BasicMap(
std::size_t initialCapacity, std::size_t initialCapacity,
......
...@@ -99,8 +99,7 @@ class F14BasicSet { ...@@ -99,8 +99,7 @@ class F14BasicSet {
public: public:
//// PUBLIC - Member functions //// PUBLIC - Member functions
F14BasicSet() noexcept(Policy::kDefaultConstructIsNoexcept) F14BasicSet() noexcept(Policy::kDefaultConstructIsNoexcept) : table_{} {}
: F14BasicSet(0) {}
explicit F14BasicSet( explicit F14BasicSet(
std::size_t initialCapacity, std::size_t initialCapacity,
......
...@@ -938,6 +938,11 @@ class F14Table : public Policy { ...@@ -938,6 +938,11 @@ class F14Table : public Policy {
} }
public: public:
// Equivalent to F14Table(0, ...), but implemented separately to avoid forcing
// a reserve() instantiation in the common case.
F14Table() noexcept(Policy::kDefaultConstructIsNoexcept)
: Policy{Hasher{}, KeyEqual{}, Alloc{}} {}
F14Table( F14Table(
std::size_t initialCapacity, std::size_t initialCapacity,
Hasher const& hasher, Hasher const& hasher,
......
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