Skip to content

Commit

Permalink
Export of internal Abseil changes
Browse files Browse the repository at this point in the history
--
8e04df6fcbd062e5eaf179a6ec9b0a26f8aa8a39 by Abseil Team <[email protected]>:

Use a floating point type for the example usage of absl::uniform_real_distribution.

PiperOrigin-RevId: 271167776

--
5f8f1dfea50bc16a9d9af3e50c4636500a938b29 by Abseil Team <[email protected]>:

the llvm wasm backend does not support this data symbol in text section, so remove it from the test.

PiperOrigin-RevId: 271138100

--
2874542cb212962ac3093fd78fd5e1eb85c126c0 by Xiaoyi Zhang <[email protected]>:

Work around MSVC 2019 compiler bug related to constexpr in optional_test.
The change in optional_test is necessary to avoid another bug on MSVC
complaining about accessing invalid member of union, and also makes the test
more reasonale by checking the value of a non-static member.

Filed a bug against MSVC
https://developercommunity.visualstudio.com/content/problem/743998/internal-compiler-error-related-to-constexpr-and-u.html.

PiperOrigin-RevId: 271129805

--
3a5d56f0c3362aabf68938fb95c4e2d3eca59538 by Abseil Team <[email protected]>:

Improve precision of absl::GetCurrentTimeNanos() by adjusting
cycle time sooner.

PiperOrigin-RevId: 271007945

--
1e044a6dec7c0ca150fff1aee52dbdb16aa43ed7 by Abseil Team <[email protected]>:

Internal change.

PiperOrigin-RevId: 270962690
GitOrigin-RevId: 8e04df6fcbd062e5eaf179a6ec9b0a26f8aa8a39
Change-Id: Icb05423a7e93ebdae16baadd59a60b75b5cfa249
  • Loading branch information
Abseil Team authored and mbxx committed Sep 25, 2019
1 parent ccdd1d5 commit 502efe6
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
7 changes: 7 additions & 0 deletions absl/container/btree_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,13 @@ TEST(Btree, MoveAssignmentAllocatorPropagation) {
}
}

TEST(Btree, EmptyTree) {
absl::btree_set<int> s;
EXPECT_TRUE(s.empty());
EXPECT_EQ(s.size(), 0);
EXPECT_GT(s.max_size(), 0);
}

} // namespace
} // namespace container_internal
} // namespace absl
9 changes: 5 additions & 4 deletions absl/container/internal/btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ class btree {
// The height of the btree. An empty tree will have height 0.
size_type height() const {
size_type h = 0;
if (root()) {
if (!empty()) {
// Count the length of the chain from the leftmost node up to the
// root. We actually count from the root back around to the level below
// the root, but the calculation is the same because of the circularity
Expand Down Expand Up @@ -1277,16 +1277,17 @@ class btree {
// divided by the maximum number of elements a tree with the current number
// of nodes could hold. A value of 1 indicates perfect space
// utilization. Smaller values indicate space wastage.
// Returns 0 for empty trees.
double fullness() const {
if (empty()) return 0.0;
return static_cast<double>(size()) / (nodes() * kNodeValues);
}
// The overhead of the btree structure in bytes per node. Computed as the
// total number of bytes used by the btree minus the number of bytes used for
// storing elements divided by the number of elements.
// Returns 0 for empty trees.
double overhead() const {
if (empty()) {
return 0.0;
}
if (empty()) return 0.0;
return (bytes_used() - size() * sizeof(value_type)) /
static_cast<double>(size());
}
Expand Down
4 changes: 4 additions & 0 deletions absl/debugging/symbolize_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static ABSL_PER_THREAD_TLS_KEYWORD char
symbolize_test_thread_big[2 * 1024 * 1024];
#endif

#if !defined(__EMSCRIPTEN__)
// Used below to hopefully inhibit some compiler/linker optimizations
// that may remove kHpageTextPadding, kPadding0, and kPadding1 from
// the binary.
Expand All @@ -89,6 +90,7 @@ static volatile bool volatile_bool = false;
static constexpr size_t kHpageSize = 1 << 21;
const char kHpageTextPadding[kHpageSize * 4] ABSL_ATTRIBUTE_SECTION_VARIABLE(
.text) = "";
#endif // !defined(__EMSCRIPTEN__)

static char try_symbolize_buffer[4096];

Expand Down Expand Up @@ -498,10 +500,12 @@ TEST(Symbolize, Unimplemented) {
#endif

int main(int argc, char **argv) {
#if !defined(__EMSCRIPTEN__)
// Make sure kHpageTextPadding is linked into the binary.
if (volatile_bool) {
ABSL_RAW_LOG(INFO, "%s", kHpageTextPadding);
}
#endif // !defined(__EMSCRIPTEN__)

#if ABSL_PER_THREAD_TLS
// Touch the per-thread variables.
Expand Down
2 changes: 1 addition & 1 deletion absl/random/uniform_real_distribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace absl {
//
// // Use the distribution to produce a value between 0.0 (inclusive)
// // and 1.0 (exclusive).
// int value = absl::uniform_real_distribution<double>(0, 1)(gen);
// double value = absl::uniform_real_distribution<double>(0, 1)(gen);
//
template <typename RealType = double>
class uniform_real_distribution {
Expand Down
2 changes: 1 addition & 1 deletion absl/time/clock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ static uint64_t UpdateLastSample(uint64_t now_cycles, uint64_t now_ns,
last_sample.min_cycles_per_sample.store(0, std::memory_order_relaxed);
stats_initializations++;
} else if (sample->raw_ns + 500 * 1000 * 1000 < now_ns &&
sample->base_cycles + 100 < now_cycles) {
sample->base_cycles + 50 < now_cycles) {
// Enough time has passed to compute the cycle time.
if (sample->nsscaled_per_cycle != 0) { // Have a cycle time estimate.
// Compute time from counter reading, but avoiding overflow
Expand Down
4 changes: 2 additions & 2 deletions absl/types/internal/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class optional_data_dtor_base {
bool engaged_;
// Data storage
union {
dummy_type dummy_;
T data_;
dummy_type dummy_;
};

void destruct() noexcept {
Expand Down Expand Up @@ -119,8 +119,8 @@ class optional_data_dtor_base<T, true> {
bool engaged_;
// Data storage
union {
dummy_type dummy_;
T data_;
dummy_type dummy_;
};
void destruct() noexcept { engaged_ = false; }

Expand Down
6 changes: 3 additions & 3 deletions absl/types/optional_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ TEST(optionalTest, Swap) {

template <int v>
struct DeletedOpAddr {
constexpr static const int value = v;
int value = v;
constexpr DeletedOpAddr() = default;
constexpr const DeletedOpAddr<v>* operator&() const = delete; // NOLINT
DeletedOpAddr<v>* operator&() = delete; // NOLINT
Expand All @@ -954,9 +954,9 @@ struct DeletedOpAddr {
// to document the fact that the current implementation of absl::optional<T>
// expects such usecases to be malformed and not compile.
TEST(optionalTest, OperatorAddr) {
constexpr const int v = -1;
constexpr int v = -1;
{ // constexpr
constexpr const absl::optional<DeletedOpAddr<v>> opt(absl::in_place_t{});
constexpr absl::optional<DeletedOpAddr<v>> opt(absl::in_place_t{});
static_assert(opt.has_value(), "");
// static_assert(opt->value == v, "");
static_assert((*opt).value == v, "");
Expand Down

0 comments on commit 502efe6

Please sign in to comment.