summaryrefslogtreecommitdiff
path: root/absl/container
diff options
context:
space:
mode:
Diffstat (limited to 'absl/container')
-rw-r--r--absl/container/fixed_array.h2
-rw-r--r--absl/container/inlined_vector.h2
-rw-r--r--absl/container/inlined_vector_benchmark.cc37
-rw-r--r--absl/container/internal/test_instance_tracker.cc2
-rw-r--r--absl/container/internal/test_instance_tracker.h2
5 files changed, 32 insertions, 13 deletions
diff --git a/absl/container/fixed_array.h b/absl/container/fixed_array.h
index 06bc8009..daa4eb22 100644
--- a/absl/container/fixed_array.h
+++ b/absl/container/fixed_array.h
@@ -50,6 +50,7 @@
#include "absl/memory/memory.h"
namespace absl {
+inline namespace lts_2018_06_20 {
constexpr static auto kFixedArrayUseDefault = static_cast<size_t>(-1);
@@ -494,5 +495,6 @@ constexpr size_t FixedArray<T, N>::inline_elements;
template <typename T, size_t N>
constexpr size_t FixedArray<T, N>::kInlineBytesDefault;
+} // inline namespace lts_2018_06_20
} // namespace absl
#endif // ABSL_CONTAINER_FIXED_ARRAY_H_
diff --git a/absl/container/inlined_vector.h b/absl/container/inlined_vector.h
index 78f78ea7..183ade54 100644
--- a/absl/container/inlined_vector.h
+++ b/absl/container/inlined_vector.h
@@ -53,6 +53,7 @@
#include "absl/memory/memory.h"
namespace absl {
+inline namespace lts_2018_06_20 {
// -----------------------------------------------------------------------------
// InlinedVector
@@ -1379,6 +1380,7 @@ auto InlinedVector<T, N, A>::InsertWithRange(const_iterator position,
return it_pair.first;
}
+} // inline namespace lts_2018_06_20
} // namespace absl
#endif // ABSL_CONTAINER_INLINED_VECTOR_H_
diff --git a/absl/container/inlined_vector_benchmark.cc b/absl/container/inlined_vector_benchmark.cc
index 5977bc93..24f21749 100644
--- a/absl/container/inlined_vector_benchmark.cc
+++ b/absl/container/inlined_vector_benchmark.cc
@@ -63,18 +63,34 @@ void BM_StdVectorFill(benchmark::State& state) {
}
BENCHMARK(BM_StdVectorFill)->Range(0, 1024);
+// The purpose of the next two benchmarks is to verify that
+// absl::InlinedVector is efficient when moving is more efficent than
+// copying. To do so, we use strings that are larger than the short
+// std::string optimization.
bool StringRepresentedInline(std::string s) {
const char* chars = s.data();
std::string s1 = std::move(s);
return s1.data() != chars;
}
+int GetNonShortStringOptimizationSize() {
+ for (int i = 24; i <= 192; i *= 2) {
+ if (!StringRepresentedInline(std::string(i, 'A'))) {
+ return i;
+ }
+ }
+ ABSL_RAW_LOG(
+ FATAL,
+ "Failed to find a std::string larger than the short std::string optimization");
+ return -1;
+}
+
void BM_InlinedVectorFillString(benchmark::State& state) {
const int len = state.range(0);
- std::string strings[4] = {"a quite long string",
- "another long string",
- "012345678901234567",
- "to cause allocation"};
+ const int no_sso = GetNonShortStringOptimizationSize();
+ std::string strings[4] = {std::string(no_sso, 'A'), std::string(no_sso, 'B'),
+ std::string(no_sso, 'C'), std::string(no_sso, 'D')};
+
for (auto _ : state) {
absl::InlinedVector<std::string, 8> v;
for (int i = 0; i < len; i++) {
@@ -87,10 +103,10 @@ BENCHMARK(BM_InlinedVectorFillString)->Range(0, 1024);
void BM_StdVectorFillString(benchmark::State& state) {
const int len = state.range(0);
- std::string strings[4] = {"a quite long string",
- "another long string",
- "012345678901234567",
- "to cause allocation"};
+ const int no_sso = GetNonShortStringOptimizationSize();
+ std::string strings[4] = {std::string(no_sso, 'A'), std::string(no_sso, 'B'),
+ std::string(no_sso, 'C'), std::string(no_sso, 'D')};
+
for (auto _ : state) {
std::vector<std::string> v;
for (int i = 0; i < len; i++) {
@@ -98,11 +114,6 @@ void BM_StdVectorFillString(benchmark::State& state) {
}
}
state.SetItemsProcessed(static_cast<int64_t>(state.iterations()) * len);
- // The purpose of the benchmark is to verify that inlined vector is
- // efficient when moving is more efficent than copying. To do so, we
- // use strings that are larger than the small std::string optimization.
- ABSL_RAW_CHECK(!StringRepresentedInline(strings[0]),
- "benchmarked with strings that are too small");
}
BENCHMARK(BM_StdVectorFillString)->Range(0, 1024);
diff --git a/absl/container/internal/test_instance_tracker.cc b/absl/container/internal/test_instance_tracker.cc
index fe00aca8..d1aa0978 100644
--- a/absl/container/internal/test_instance_tracker.cc
+++ b/absl/container/internal/test_instance_tracker.cc
@@ -15,6 +15,7 @@
#include "absl/container/internal/test_instance_tracker.h"
namespace absl {
+inline namespace lts_2018_06_20 {
namespace test_internal {
int BaseCountedInstance::num_instances_ = 0;
int BaseCountedInstance::num_live_instances_ = 0;
@@ -23,4 +24,5 @@ int BaseCountedInstance::num_copies_ = 0;
int BaseCountedInstance::num_swaps_ = 0;
} // namespace test_internal
+} // inline namespace lts_2018_06_20
} // namespace absl
diff --git a/absl/container/internal/test_instance_tracker.h b/absl/container/internal/test_instance_tracker.h
index cf8f3a53..b4a84656 100644
--- a/absl/container/internal/test_instance_tracker.h
+++ b/absl/container/internal/test_instance_tracker.h
@@ -19,6 +19,7 @@
#include <ostream>
namespace absl {
+inline namespace lts_2018_06_20 {
namespace test_internal {
// A type that counts number of occurences of the type, the live occurrences of
@@ -215,6 +216,7 @@ class MovableOnlyInstance : public BaseCountedInstance {
};
} // namespace test_internal
+} // inline namespace lts_2018_06_20
} // namespace absl
#endif // ABSL_CONTAINER_INTERNAL_TEST_INSTANCE_TRACKER_H_