Skip to content

Commit

Permalink
Changes imported from Abseil "staging" branch:
Browse files Browse the repository at this point in the history
  - a42e9b454ca8be7d021789cdb9bcada07d3e2d3e Merge pull request #57. by Derek Mauro <dmauro@google.com>
  - b1e03838f059c034a6489501804d516326246042 Move the long ostream tests into a separate source file u... by Alex Strelnikov <strel@google.com>
  - 7c56b7dbb05faa7e8653632e00be470331d79cb9 Return reference from absl::InlinedVector::emplace_back(). by Abseil Team <absl-team@google.com>
  - 85b070822b62688ff348d9ad9cc9e230a851f617 Treat \u or \U followed by Unicode surrogate character as... by Abseil Team <absl-team@google.com>

GitOrigin-RevId: a42e9b454ca8be7d021789cdb9bcada07d3e2d3e
Change-Id: I7d8fb68ffd7eb4e9e737f21fbed6d56b71985f94
  • Loading branch information
Abseil Team authored and tituswinters committed Dec 14, 2017
1 parent 5fe41af commit 720c017
Show file tree
Hide file tree
Showing 11 changed files with 720 additions and 919 deletions.
2 changes: 1 addition & 1 deletion absl/base/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
// POSIX.1-2001.
#ifdef ABSL_HAVE_MMAP
#error ABSL_HAVE_MMAP cannot be directly set
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
defined(__Fuchsia__)
#define ABSL_HAVE_MMAP 1
Expand Down
19 changes: 12 additions & 7 deletions absl/container/inlined_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,14 @@ class InlinedVector {
// InlinedVector::emplace_back()
//
// Constructs and appends an object to the inlined vector.
//
// Returns a reference to the inserted element.
template <typename... Args>
void emplace_back(Args&&... args) {
value_type& emplace_back(Args&&... args) {
size_type s = size();
assert(s <= capacity());
if (ABSL_PREDICT_FALSE(s == capacity())) {
GrowAndEmplaceBack(std::forward<Args>(args)...);
return;
return GrowAndEmplaceBack(std::forward<Args>(args)...);
}
assert(s < capacity());

Expand All @@ -383,7 +384,7 @@ class InlinedVector {
tag().set_inline_size(s + 1);
space = inlined_space();
}
Construct(space + s, std::forward<Args>(args)...);
return Construct(space + s, std::forward<Args>(args)...);
}

// InlinedVector::push_back()
Expand Down Expand Up @@ -703,26 +704,30 @@ class InlinedVector {
}

template <typename... Args>
void GrowAndEmplaceBack(Args&&... args) {
value_type& GrowAndEmplaceBack(Args&&... args) {
assert(size() == capacity());
const size_type s = size();

Allocation new_allocation(allocator(), 2 * capacity());

Construct(new_allocation.buffer() + s, std::forward<Args>(args)...);
value_type& new_element =
Construct(new_allocation.buffer() + s, std::forward<Args>(args)...);
UninitializedCopy(std::make_move_iterator(data()),
std::make_move_iterator(data() + s),
new_allocation.buffer());

ResetAllocation(new_allocation, s + 1);

return new_element;
}

void InitAssign(size_type n);
void InitAssign(size_type n, const value_type& t);

template <typename... Args>
void Construct(pointer p, Args&&... args) {
value_type& Construct(pointer p, Args&&... args) {
AllocatorTraits::construct(allocator(), p, std::forward<Args>(args)...);
return *p;
}

template <typename Iter>
Expand Down
13 changes: 13 additions & 0 deletions absl/container/inlined_vector_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,19 @@ TEST(InlinedVectorTest, Noexcept) {
absl::InlinedVector<MoveCanThrow, 2>>::value));
}

TEST(InlinedVectorTest, EmplaceBack) {
absl::InlinedVector<std::pair<std::string, int>, 1> v;

auto& inlined_element = v.emplace_back("answer", 42);
EXPECT_EQ(&inlined_element, &v[0]);
EXPECT_EQ(inlined_element.first, "answer");
EXPECT_EQ(inlined_element.second, 42);

auto& allocated_element = v.emplace_back("taxicab", 1729);
EXPECT_EQ(&allocated_element, &v[1]);
EXPECT_EQ(allocated_element.first, "taxicab");
EXPECT_EQ(allocated_element.second, 1729);
}

TEST(IntVec, Insert) {
for (int len = 0; len < 20; len++) {
Expand Down
2 changes: 1 addition & 1 deletion absl/debugging/internal/stacktrace_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#error ABSL_STACKTRACE_INL_HEADER cannot be directly set
#elif defined(__native_client__) || defined(__APPLE__) || \
defined(__FreeBSD__) || defined(__ANDROID__) || defined(__myriad2__) || \
defined(asmjs__) || defined(__Fuchsia__)
defined(__asmjs__) || defined(__Fuchsia__)
#define ABSL_STACKTRACE_INL_HEADER \
"absl/debugging/internal/stacktrace_unimplemented-inl.inc"

Expand Down
2 changes: 1 addition & 1 deletion absl/debugging/internal/stacktrace_powerpc-inl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static inline void *StacktracePowerPCGetLR(void **sp) {
#elif defined(_CALL_SYSV)
return *(sp+1);
#elif defined(__APPLE__) || defined(__FreeBSD__) || \
(defined(__linux__) && defined(__PPC64__))
(defined(__linux__) && defined(__PPC64__))
// This check is in case the compiler doesn't define _CALL_AIX/etc.
return *(sp+2);
#elif defined(__linux)
Expand Down
2 changes: 1 addition & 1 deletion absl/numeric/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ cc_test(
name = "int128_test",
size = "small",
srcs = [
"int128_stream_test.cc",
"int128_test.cc",
"int128_test_unsigned_ostream_cases.inc",
],
copts = ABSL_TEST_COPTS,
deps = [
Expand Down
Loading

0 comments on commit 720c017

Please sign in to comment.