projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Deflake some AsyncSSLSocket tests.
[folly.git]
/
folly
/
Padded.h
diff --git
a/folly/Padded.h
b/folly/Padded.h
index c5b53a7c94ad88c6aef460e29ffd6193dd18046d..88282d9d12c80a7f04eb0cbd9ec4d6bde2e1dd68 100644
(file)
--- a/
folly/Padded.h
+++ b/
folly/Padded.h
@@
-1,5
+1,5
@@
/*
/*
- * Copyright 201
5
Facebook, Inc.
+ * Copyright 201
7
Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-14,9
+14,9
@@
* limitations under the License.
*/
* limitations under the License.
*/
-#ifndef FOLLY_PADDED_H_
-#define FOLLY_PADDED_H_
+#pragma once
+#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <cstdint>
#include <cstring>
@@
-27,6
+27,7
@@
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
+#include <folly/ContainerTraits.h>
#include <folly/Portability.h>
/**
#include <folly/Portability.h>
/**
@@
-66,7
+67,7
@@
struct NodeValid<T, NS,
NS % alignof(T) == 0)>::type> {
typedef void type;
};
NS % alignof(T) == 0)>::type> {
typedef void type;
};
-}
// namespace detail
+} // namespace detail
template <class T, size_t NS>
class Node<T, NS, typename detail::NodeValid<T,NS>::type> {
template <class T, size_t NS>
class Node<T, NS, typename detail::NodeValid<T,NS>::type> {
@@
-189,7
+190,7
@@
struct IteratorBase {
> type;
};
> type;
};
-}
// namespace detail
+} // namespace detail
/**
* Wrapper around iterators to Node to return iterators to the underlying
/**
* Wrapper around iterators to Node to return iterators to the underlying
@@
-344,13
+345,14
@@
class Adaptor {
lastCount_(lastCount) {
}
explicit Adaptor(size_t n, const value_type& value = value_type())
lastCount_(lastCount) {
}
explicit Adaptor(size_t n, const value_type& value = value_type())
- : c_(Node::nodeCount(n), fullNode(value)),
- lastCount_(n % Node::kElementCount ?: Node::kElementCount) {
+ : c_(Node::nodeCount(n), fullNode(value)) {
+ const auto count = n % Node::kElementCount;
+ lastCount_ = count != 0 ? count : Node::kElementCount;
}
Adaptor(const Adaptor&) = default;
Adaptor& operator=(const Adaptor&) = default;
}
Adaptor(const Adaptor&) = default;
Adaptor& operator=(const Adaptor&) = default;
- Adaptor(Adaptor&& other)
+ Adaptor(Adaptor&& other)
noexcept
: c_(std::move(other.c_)),
lastCount_(other.lastCount_) {
other.lastCount_ = Node::kElementCount;
: c_(std::move(other.c_)),
lastCount_(other.lastCount_) {
other.lastCount_ = Node::kElementCount;
@@
-383,7
+385,7
@@
class Adaptor {
iterator end() {
auto it = iterator(c_.end());
if (lastCount_ != Node::kElementCount) {
iterator end() {
auto it = iterator(c_.end());
if (lastCount_ != Node::kElementCount) {
- it -= (Node::kElementCount - lastCount_);
+ it -=
difference_type
(Node::kElementCount - lastCount_);
}
return it;
}
}
return it;
}
@@
-424,12
+426,13
@@
class Adaptor {
return c_.back().data()[lastCount_ - 1];
}
return c_.back().data()[lastCount_ - 1];
}
+ template <typename... Args>
+ void emplace_back(Args&&... args) {
+ new (allocate_back()) value_type(std::forward<Args>(args)...);
+ }
+
void push_back(value_type x) {
void push_back(value_type x) {
- if (lastCount_ == Node::kElementCount) {
- c_.push_back(Node());
- lastCount_ = 0;
- }
- c_.back().data()[lastCount_++] = std::move(x);
+ emplace_back(std::move(x));
}
void pop_back() {
}
void pop_back() {
@@
-490,6
+493,14
@@
class Adaptor {
}
private:
}
private:
+ value_type* allocate_back() {
+ if (lastCount_ == Node::kElementCount) {
+ container_emplace_back_or_push_back(c_);
+ lastCount_ = 0;
+ }
+ return &c_.back().data()[lastCount_++];
+ }
+
static Node fullNode(const value_type& value) {
Node n;
std::fill(n.data(), n.data() + kElementsPerNode, value);
static Node fullNode(const value_type& value) {
Node n;
std::fill(n.data(), n.data() + kElementsPerNode, value);
@@
-499,7
+510,5
@@
class Adaptor {
size_t lastCount_; // number of elements in last Node
};
size_t lastCount_; // number of elements in last Node
};
-} // namespace padded
-} // namespace folly
-
-#endif /* FOLLY_PADDED_H_ */
+} // namespace padded
+} // namespace folly