This is an automated email from the ASF dual-hosted git repository.
wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 3124cf03 Replace NULL with nullptr in butil/containers (#3437)
3124cf03 is described below
commit 3124cf035de919bbe37e386029ebe21f3816ddb3
Author: Bright Chen <[email protected]>
AuthorDate: Sat Aug 15 13:57:09 2026 +0800
Replace NULL with nullptr in butil/containers (#3437)
---
src/butil/containers/bounded_queue.h | 40 +++++++++++-----------
src/butil/containers/doubly_buffered_data.h | 48 +++++++++++++-------------
src/butil/containers/flat_map.h | 20 +++++------
src/butil/containers/flat_map_inl.h | 52 ++++++++++++++---------------
src/butil/containers/linked_list.h | 2 +-
src/butil/containers/mpsc_queue.h | 20 +++++------
src/butil/containers/scoped_ptr_hash_map.h | 6 ++--
src/butil/containers/small_map.h | 32 +++++++++---------
src/butil/containers/stack_container.h | 8 ++---
9 files changed, 114 insertions(+), 114 deletions(-)
diff --git a/src/butil/containers/bounded_queue.h
b/src/butil/containers/bounded_queue.h
index 55f06e1e..cf093cdf 100644
--- a/src/butil/containers/bounded_queue.h
+++ b/src/butil/containers/bounded_queue.h
@@ -84,14 +84,14 @@ public:
, _cap(0)
, _start(0)
, _ownership(NOT_OWN_STORAGE)
- , _items(NULL) {
+ , _items(nullptr) {
};
~BoundedQueue() {
clear();
if (_ownership == OWNS_STORAGE) {
free(_items);
- _items = NULL;
+ _items = nullptr;
}
}
@@ -124,7 +124,7 @@ public:
if (_count < _cap) {
return new ((T*)_items + _mod(_start + _count++, _cap)) T();
}
- return NULL;
+ return nullptr;
}
// Push |item| into top side of this queue
@@ -147,7 +147,7 @@ public:
++_count;
return new ((T*)_items + _start) T();
}
- return NULL;
+ return nullptr;
}
// Pop top-most item from this queue
@@ -209,52 +209,52 @@ public:
_start = 0;
}
- // Get address of top-most item, NULL if queue is empty
- T* top() {
- return _count ? ((T*)_items + _start) : NULL;
+ // Get address of top-most item, nullptr if queue is empty
+ T* top() {
+ return _count ? ((T*)_items + _start) : nullptr;
}
- const T* top() const {
- return _count ? ((const T*)_items + _start) : NULL;
+ const T* top() const {
+ return _count ? ((const T*)_items + _start) : nullptr;
}
// Randomly access item from top side.
// top(0) == top(), top(size()-1) == bottom()
- // Returns NULL if |index| is out of range.
+ // Returns nullptr if |index| is out of range.
T* top(size_t index) {
if (index < _count) {
return (T*)_items + _mod(_start + index, _cap);
}
- return NULL; // including _count == 0
+ return nullptr; // including _count == 0
}
const T* top(size_t index) const {
if (index < _count) {
return (const T*)_items + _mod(_start + index, _cap);
}
- return NULL; // including _count == 0
+ return nullptr; // including _count == 0
}
- // Get address of bottom-most item, NULL if queue is empty
- T* bottom() {
- return _count ? ((T*)_items + _mod(_start + _count - 1, _cap)) : NULL;
+ // Get address of bottom-most item, nullptr if queue is empty
+ T* bottom() {
+ return _count ? ((T*)_items + _mod(_start + _count - 1, _cap)) :
nullptr;
}
const T* bottom() const {
- return _count ? ((const T*)_items + _mod(_start + _count - 1, _cap)) :
NULL;
+ return _count ? ((const T*)_items + _mod(_start + _count - 1, _cap)) :
nullptr;
}
// Randomly access item from bottom side.
// bottom(0) == bottom(), bottom(size()-1) == top()
- // Returns NULL if |index| is out of range.
+ // Returns nullptr if |index| is out of range.
T* bottom(size_t index) {
if (index < _count) {
return (T*)_items + _mod(_start + _count - index - 1, _cap);
}
- return NULL; // including _count == 0
+ return nullptr; // including _count == 0
}
const T* bottom(size_t index) const {
if (index < _count) {
return (const T*)_items + _mod(_start + _count - index - 1, _cap);
}
- return NULL; // including _count == 0
+ return nullptr; // including _count == 0
}
bool empty() const { return !_count; }
@@ -270,7 +270,7 @@ public:
size_t max_capacity() const { return (1UL << (sizeof(_cap) * 8)) - 1; }
// True if the queue was constructed successfully.
- bool initialized() const { return _items != NULL; }
+ bool initialized() const { return _items != nullptr; }
// Swap internal fields with another queue.
void swap(BoundedQueue& rhs) {
diff --git a/src/butil/containers/doubly_buffered_data.h
b/src/butil/containers/doubly_buffered_data.h
index 8ba54ac0..410da3f0 100644
--- a/src/butil/containers/doubly_buffered_data.h
+++ b/src/butil/containers/doubly_buffered_data.h
@@ -94,7 +94,7 @@ public:
class ScopedPtr {
friend class DoublyBufferedData;
public:
- ScopedPtr() : _data(NULL), _index(0), _w(NULL) {}
+ ScopedPtr() : _data(nullptr), _index(0), _w(nullptr) {}
~ScopedPtr() {
if (_w) {
if (AllowBthreadSuspended) {
@@ -202,7 +202,7 @@ public:
struct BAIDU_CACHELINE_ALIGNMENT ThreadBlock {
WrapperSharedPtr at(size_t offset) {
- if (NULL == _data[offset]) {
+ if (nullptr == _data[offset]) {
_data[offset] = std::make_shared<Wrapper>();
}
return _data[offset];
@@ -237,9 +237,9 @@ public:
static WrapperSharedPtr get_or_create_tls_data(WrapperTLSId id) {
if (BAIDU_UNLIKELY(id < 0)) {
CHECK(false) << "Invalid id=" << id;
- return NULL;
+ return nullptr;
}
- if (_s_tls_blocks == NULL) {
+ if (_s_tls_blocks == nullptr) {
_s_tls_blocks = new std::vector<ThreadBlock*>;
butil::thread_atexit(_destroy_tls_blocks);
}
@@ -249,7 +249,7 @@ public:
_s_tls_blocks->resize(std::max(block_id + 1, 32ul));
}
ThreadBlock* tb = (*_s_tls_blocks)[block_id];
- if (tb == NULL) {
+ if (tb == nullptr) {
tb = new ThreadBlock;
(*_s_tls_blocks)[block_id] = tb;
}
@@ -265,7 +265,7 @@ private:
delete (*_s_tls_blocks)[i];
}
delete _s_tls_blocks;
- _s_tls_blocks = NULL;
+ _s_tls_blocks = nullptr;
}
inline static std::deque<WrapperTLSId>& _get_free_ids() {
@@ -288,7 +288,7 @@ pthread_mutex_t DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::WrapperTLSGro
template <typename T, typename TLS, bool AllowBthreadSuspended>
std::deque<typename DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::WrapperTLSId>*
- DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::WrapperTLSGroup::_s_free_ids = NULL;
+ DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::WrapperTLSGroup::_s_free_ids = nullptr;
template <typename T, typename TLS, bool AllowBthreadSuspended>
typename DoublyBufferedData<T, TLS, AllowBthreadSuspended>::WrapperTLSId
@@ -296,7 +296,7 @@ typename DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::WrapperTLSId
template <typename T, typename TLS, bool AllowBthreadSuspended>
__thread std::vector<typename DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::WrapperTLSGroup::ThreadBlock*>*
- DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::WrapperTLSGroup::_s_tls_blocks = NULL;
+ DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::WrapperTLSGroup::_s_tls_blocks = nullptr;
template <typename T, typename TLS, bool AllowBthreadSuspended>
class BAIDU_CACHELINE_ALIGNMENT DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::Wrapper
@@ -304,12 +304,12 @@ class BAIDU_CACHELINE_ALIGNMENT DoublyBufferedData<T,
TLS, AllowBthreadSuspended
friend class DoublyBufferedData;
public:
explicit Wrapper()
- : _control(NULL)
+ : _control(nullptr)
, _modify_wait(false) {
- pthread_mutex_init(&_mutex, NULL);
+ pthread_mutex_init(&_mutex, nullptr);
if (AllowBthreadSuspended) {
- pthread_cond_init(&_cond[0], NULL);
- pthread_cond_init(&_cond[1], NULL);
+ pthread_cond_init(&_cond[0], nullptr);
+ pthread_cond_init(&_cond[1], nullptr);
}
}
@@ -403,15 +403,15 @@ template <typename T, typename TLS, bool
AllowBthreadSuspended>
typename DoublyBufferedData<T, TLS, AllowBthreadSuspended>::WrapperSharedPtr
DoublyBufferedData<T, TLS, AllowBthreadSuspended>::GetWrapper() {
WrapperSharedPtr w = WrapperTLSGroup::get_or_create_tls_data(_wrapper_key);
- if (NULL == w) {
- return NULL;
+ if (nullptr == w) {
+ return nullptr;
}
if (w->_control == this) {
return w;
}
- if (w->_control != NULL) {
+ if (w->_control != nullptr) {
LOG(FATAL) << "Get wrapper from tls but control != this";
- return NULL;
+ return nullptr;
}
try {
w->_control = this;
@@ -425,7 +425,7 @@ DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::GetWrapper() {
}),
_wrappers.end());
} catch (std::exception& e) {
- return NULL;
+ return nullptr;
}
return w;
}
@@ -438,11 +438,11 @@ DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::DoublyBufferedData()
"Forbidden to allow bthread suspended with non-Void TLS");
_wrappers.reserve(64);
- pthread_mutex_init(&_modify_mutex, NULL);
- pthread_mutex_init(&_wrappers_mutex, NULL);
+ pthread_mutex_init(&_modify_mutex, nullptr);
+ pthread_mutex_init(&_wrappers_mutex, nullptr);
_wrapper_key = WrapperTLSGroup::key_create();
// Initialize _data for some POD types. This is essential for pointer
- // types because they should be Read() as NULL before any Modify().
+ // types because they should be Read() as nullptr before any Modify().
if (is_integral<T>::value || is_floating_point<T>::value ||
is_pointer<T>::value || is_member_function_pointer<T>::value) {
_data[0] = T();
@@ -459,8 +459,8 @@ DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::~DoublyBufferedData() {
BAIDU_SCOPED_LOCK(_wrappers_mutex);
for (size_t i = 0; i < _wrappers.size(); ++i) {
WrapperSharedPtr w = _wrappers[i].lock();
- if (NULL != w) {
- w->_control = NULL; // hack: disable removal.
+ if (nullptr != w) {
+ w->_control = nullptr; // hack: disable removal.
}
}
_wrappers.clear();
@@ -475,7 +475,7 @@ template <typename T, typename TLS, bool
AllowBthreadSuspended>
int DoublyBufferedData<T, TLS, AllowBthreadSuspended>::Read(
typename DoublyBufferedData<T, TLS, AllowBthreadSuspended>::ScopedPtr*
ptr) {
WrapperSharedPtr w = GetWrapper();
- if (BAIDU_UNLIKELY(w == NULL)) {
+ if (BAIDU_UNLIKELY(w == nullptr)) {
return -1;
}
@@ -541,7 +541,7 @@ size_t DoublyBufferedData<T, TLS,
AllowBthreadSuspended>::Modify(Fn&& fn, Args&&
std::remove_if(_wrappers.begin(), _wrappers.end(),
[bg_index](const WrapperWeakPtr& weak) {
WrapperSharedPtr w = weak.lock();
- bool expired = NULL == w;
+ bool expired = nullptr == w;
if (!expired) {
// Notify all threads waiting for read done.
if (AllowBthreadSuspended) {
diff --git a/src/butil/containers/flat_map.h b/src/butil/containers/flat_map.h
index 54981b81..ca86dfd7 100644
--- a/src/butil/containers/flat_map.h
+++ b/src/butil/containers/flat_map.h
@@ -187,12 +187,12 @@ public:
// Insert a pair of |key| and |value|. If size()*100/bucket_count() is
// more than load_factor(), a resize() will be done.
- // Returns address of the inserted value, NULL on error.
+ // Returns address of the inserted value, nullptr on error.
mapped_type* insert(const key_type& key, const mapped_type& value);
// Insert a pair of {key, value}. If size()*100/bucket_count() is
// more than load_factor(), a resize() will be done.
- // Returns address of the inserted value, NULL on error.
+ // Returns address of the inserted value, nullptr on error.
mapped_type* insert(const std::pair<key_type, mapped_type>& kv);
// For `_Multi=false'. (Default)
@@ -200,12 +200,12 @@ public:
// Returns: 1 on erased, 0 otherwise.
template <typename K2, bool Multi = _Multi>
typename std::enable_if<!Multi, size_t>::type
- erase(const K2& key, mapped_type* old_value = NULL);
+ erase(const K2& key, mapped_type* old_value = nullptr);
// For `_Multi=true'.
// Returns: num of value on erased, 0 otherwise.
template <typename K2, bool Multi = _Multi>
typename std::enable_if<Multi, size_t>::type
- erase(const K2& key, std::vector<mapped_type>* old_values = NULL);
+ erase(const K2& key, std::vector<mapped_type>* old_values = nullptr);
// Remove all items. Allocated spaces are NOT returned by system.
void clear();
@@ -269,7 +269,7 @@ public:
const_iterator restore_iterator(const PositionHint&) const;
// Always returns true.
- bool initialized() const { return _buckets != NULL; }
+ bool initialized() const { return _buckets != nullptr; }
bool empty() const { return _size == 0; }
size_t size() const { return _size; }
@@ -281,10 +281,10 @@ public:
struct Bucket {
Bucket() : next((Bucket*)-1UL) {}
- explicit Bucket(const _K& k) : next(NULL) {
+ explicit Bucket(const _K& k) : next(nullptr) {
element_space_.Init(k);
}
- Bucket(const Bucket& other) : next(NULL) {
+ Bucket(const Bucket& other) : next(nullptr) {
element_space_.Init(other.element());
}
@@ -322,7 +322,7 @@ template <typename _Map, typename _Element> friend class
SparseFlatMapIterator;
struct NewBucketsInfo {
NewBucketsInfo()
- : buckets(NULL), thumbnail(NULL), nbucket(0) {}
+ : buckets(nullptr), thumbnail(nullptr), nbucket(0) {}
NewBucketsInfo(Bucket* b, uint64_t* t, size_t n)
: buckets(b), thumbnail(t), nbucket(n) {}
@@ -370,7 +370,7 @@ template <typename _Map, typename _Element> friend class
SparseFlatMapIterator;
for (size_t i = 0; i < nbucket; ++i) {
buckets[i].set_invalid();
}
- buckets[nbucket].next = NULL;
+ buckets[nbucket].next = nullptr;
if (_Sparse) {
bit_array_clear(thumbnail, nbucket);
}
@@ -431,7 +431,7 @@ public:
{ return _map.insert(key, FlatMapVoid()); }
template <typename K2>
- size_t erase(const K2& key) { return _map.erase(key, NULL); }
+ size_t erase(const K2& key) { return _map.erase(key, nullptr); }
void clear() { return _map.clear(); }
void clear_and_reset_pool() { return _map.clear_and_reset_pool(); }
diff --git a/src/butil/containers/flat_map_inl.h
b/src/butil/containers/flat_map_inl.h
index 93bcbf9d..d14d0db5 100644
--- a/src/butil/containers/flat_map_inl.h
+++ b/src/butil/containers/flat_map_inl.h
@@ -88,7 +88,7 @@ public:
typedef ptrdiff_t difference_type;
typedef typename remove_const<Value>::type NonConstValue;
- FlatMapIterator() : _node(NULL), _entry(NULL) {}
+ FlatMapIterator() : _node(nullptr), _entry(nullptr) {}
FlatMapIterator(const Map* map, size_t pos) {
_entry = map->_buckets + pos;
find_and_set_valid_node();
@@ -107,7 +107,7 @@ public:
// ++ it
FlatMapIterator& operator++() {
- if (NULL == _node->next) {
+ if (nullptr == _node->next) {
++_entry;
find_and_set_valid_node();
} else {
@@ -156,7 +156,7 @@ public:
typedef ptrdiff_t difference_type;
typedef typename remove_const<Value>::type NonConstValue;
- SparseFlatMapIterator() : _node(NULL), _pos(0), _map(NULL) {}
+ SparseFlatMapIterator() : _node(nullptr), _pos(0), _map(nullptr) {}
SparseFlatMapIterator(const Map* map, size_t pos) {
_map = map;
_pos = pos;
@@ -177,7 +177,7 @@ public:
// ++ it
SparseFlatMapIterator& operator++() {
- if (NULL == _node->next) {
+ if (nullptr == _node->next) {
++_pos;
find_and_set_valid_node();
} else {
@@ -221,7 +221,7 @@ FlatMap<_K, _T, _H, _E, _S, _A, _M>::FlatMap(const hasher&
hashfn,
: _size(0)
, _nbucket(DEFAULT_NBUCKET)
, _buckets((Bucket*)(&_default_buckets))
- , _thumbnail(_S ? _default_thumbnail : NULL)
+ , _thumbnail(_S ? _default_thumbnail : nullptr)
, _load_factor(80)
, _is_default_load_factor(true)
, _hashfn(hashfn)
@@ -246,9 +246,9 @@ FlatMap<_K, _T, _H, _E, _S, _A, _M>::~FlatMap() {
clear();
if (!is_default_buckets()) {
get_allocator().Free(_buckets);
- _buckets = NULL;
+ _buckets = nullptr;
bit_array_free(_thumbnail);
- _thumbnail = NULL;
+ _thumbnail = nullptr;
}
_nbucket = 0;
_load_factor = 0;
@@ -304,7 +304,7 @@ FlatMap<_K, _T, _H, _E, _S, _A, _M>::operator=(
}
}
}
- _buckets[rhs._nbucket].next = NULL;
+ _buckets[rhs._nbucket].next = nullptr;
_size = rhs._size;
} else {
for (const_iterator it = rhs.begin(); it != rhs.end(); ++it) {
@@ -396,7 +396,7 @@ FlatMap<_K, _T, _H, _E, _S, _A, _M>::erase(const K2& key,
_T* old_value) {
if (old_value) {
*old_value = first_node.element().second_movable_ref();
}
- if (first_node.next == NULL) {
+ if (first_node.next == nullptr) {
first_node.destroy_element();
first_node.set_invalid();
if (_S) {
@@ -459,13 +459,13 @@ FlatMap<_K, _T, _H, _E, _S, _A, _M>::erase(
return 0;
}
- Bucket* new_head = NULL;
- Bucket* new_tail = NULL;
+ Bucket* new_head = nullptr;
+ Bucket* new_tail = nullptr;
Bucket* p = &first_node;
size_t total = _size;
- while (NULL != p) {
+ while (nullptr != p) {
if (_eql(p->element().first_ref(), key)) {
- if (NULL != old_values) {
+ if (nullptr != old_values) {
old_values->push_back(p->element().second_movable_ref());
}
Bucket* temp = p;
@@ -476,7 +476,7 @@ FlatMap<_K, _T, _H, _E, _S, _A, _M>::erase(
}
--_size;
} else {
- if (NULL == new_head) {
+ if (nullptr == new_head) {
new_head = p;
new_tail = p;
} else {
@@ -486,10 +486,10 @@ FlatMap<_K, _T, _H, _E, _S, _A, _M>::erase(
p = p->next;
}
}
- if (NULL != new_tail) {
- new_tail->next = NULL;
+ if (nullptr != new_tail) {
+ new_tail->next = nullptr;
}
- if (NULL == new_head) {
+ if (nullptr == new_head) {
// Erase all element.
first_node.set_invalid();
if (_S) {
@@ -514,7 +514,7 @@ void FlatMap<_K, _T, _H, _E, _S, _A, _M>::clear() {
return;
}
_size = 0;
- if (NULL != _buckets) {
+ if (nullptr != _buckets) {
for (size_t i = 0; i < _nbucket; ++i) {
Bucket& first_node = _buckets[i];
if (first_node.is_valid()) {
@@ -530,7 +530,7 @@ void FlatMap<_K, _T, _H, _E, _S, _A, _M>::clear() {
}
}
}
- if (NULL != _thumbnail) {
+ if (nullptr != _thumbnail) {
bit_array_clear(_thumbnail, _nbucket);
}
}
@@ -548,7 +548,7 @@ template <typename K2>
_T* FlatMap<_K, _T, _H, _E, _S, _A, _M>::seek(const K2& key) const {
Bucket& first_node = _buckets[flatmap_mod(_hashfn(key), _nbucket)];
if (!first_node.is_valid()) {
- return NULL;
+ return nullptr;
}
if (_eql(first_node.element().first_ref(), key)) {
return &first_node.element().second_ref();
@@ -560,7 +560,7 @@ _T* FlatMap<_K, _T, _H, _E, _S, _A, _M>::seek(const K2&
key) const {
}
p = p->next;
}
- return NULL;
+ return nullptr;
}
template <typename _K, typename _T, typename _H, typename _E,
@@ -605,7 +605,7 @@ FlatMap<_K, _T, _H, _E, _S, _A, _M>::operator[](const
key_type& key) {
if (_eql(p->element().first_ref(), key)) {
return p->element().second_ref();
}
- if (NULL == p->next) {
+ if (nullptr == p->next) {
if (is_too_crowded(_size) && resize(_nbucket + 1)) {
return operator[](key);
}
@@ -637,7 +637,7 @@ FlatMap<_K, _T, _H, _E, _S, _A, _M>::operator[](const
key_type& key) {
if (is_too_crowded(_size)) {
Bucket *p = &first_node;
bool need_scale = false;
- while (NULL != p) {
+ while (nullptr != p) {
// Increase the capacity of bucket when
// hash collision occur and map is crowded.
if (!_eql(p->element().first_ref(), key)) {
@@ -731,15 +731,15 @@ FlatMap<_K, _T, _H, _E, _S, _A,
_M>::new_buckets_and_thumbnail(size_t size,
auto guard = MakeScopeGuard([buckets, this]() {
get_allocator().Free(buckets);
});
- if (NULL == buckets) {
+ if (nullptr == buckets) {
LOG(FATAL) << "Fail to new Buckets";
return nullopt;
}
- uint64_t* thumbnail = NULL;
+ uint64_t* thumbnail = nullptr;
if (_S) {
thumbnail = bit_array_malloc(new_nbucket);
- if (NULL == thumbnail) {
+ if (nullptr == thumbnail) {
LOG(FATAL) << "Fail to new thumbnail";
return nullopt;
}
diff --git a/src/butil/containers/linked_list.h
b/src/butil/containers/linked_list.h
index 7874b65a..c15cabdc 100644
--- a/src/butil/containers/linked_list.h
+++ b/src/butil/containers/linked_list.h
@@ -128,7 +128,7 @@ class LinkNode {
void RemoveFromList() {
this->previous_->next_ = this->next_;
this->next_->previous_ = this->previous_;
- // next() and previous() return non-NULL if and only this node is not in
any
+ // next() and previous() return non-nullptr if and only this node is not
in any
// list.
this->next_ = this;
this->previous_ = this;
diff --git a/src/butil/containers/mpsc_queue.h
b/src/butil/containers/mpsc_queue.h
index 6ba09db3..505b0a27 100644
--- a/src/butil/containers/mpsc_queue.h
+++ b/src/butil/containers/mpsc_queue.h
@@ -32,7 +32,7 @@ template <typename T>
struct BAIDU_CACHELINE_ALIGNMENT MPSCQueueNode {
static MPSCQueueNode* const UNCONNECTED;
- MPSCQueueNode* next{NULL};
+ MPSCQueueNode* next{nullptr};
ManualConstructor<T> data_mem;
};
@@ -60,9 +60,9 @@ template <typename T, typename Alloc = DefaultAllocator<T>>
class MPSCQueue {
public:
MPSCQueue()
- : _head(NULL)
- , _cur_enqueue_node(NULL)
- , _cur_dequeue_node(NULL) {}
+ : _head(nullptr)
+ , _cur_enqueue_node(nullptr)
+ , _cur_dequeue_node(nullptr) {}
~MPSCQueue();
@@ -88,7 +88,7 @@ private:
template <typename T, typename Alloc>
MPSCQueue<T, Alloc>::~MPSCQueue() {
- while (DequeueImpl(NULL));
+ while (DequeueImpl(nullptr));
}
template <typename T, typename Alloc>
@@ -114,7 +114,7 @@ void MPSCQueue<T, Alloc>::EnqueueImpl(MPSCQueueNode<T>*
node) {
node->next = prev;
return;
}
- node->next = NULL;
+ node->next = nullptr;
_cur_enqueue_node.store(node, memory_order_relaxed);
}
@@ -129,7 +129,7 @@ bool MPSCQueue<T, Alloc>::DequeueImpl(T* data) {
if (_cur_dequeue_node) {
node = _cur_dequeue_node;
} else {
- node = _cur_enqueue_node.exchange(NULL, memory_order_relaxed);
+ node = _cur_enqueue_node.exchange(nullptr, memory_order_relaxed);
}
if (!node) {
return false;
@@ -151,9 +151,9 @@ bool MPSCQueue<T, Alloc>::DequeueImpl(T* data) {
template <typename T, typename Alloc>
void MPSCQueue<T, Alloc>::ReverseList(MPSCQueueNode<T>* old_head) {
- // Try to set _write_head to NULL to mark that it is done.
+ // Try to set _write_head to nullptr to mark that it is done.
MPSCQueueNode<T>* new_head = old_head;
- MPSCQueueNode<T>* desired = NULL;
+ MPSCQueueNode<T>* desired = nullptr;
if (_head.compare_exchange_strong(
new_head, desired, memory_order_acquire)) {
// No one added new requests.
@@ -165,7 +165,7 @@ void MPSCQueue<T, Alloc>::ReverseList(MPSCQueueNode<T>*
old_head) {
// Someone added new requests.
// Reverse the list until old_head.
- MPSCQueueNode<T>* tail = NULL;
+ MPSCQueueNode<T>* tail = nullptr;
MPSCQueueNode<T>* p = new_head;
do {
while (p->next == MPSCQueueNode<T>::UNCONNECTED) {
diff --git a/src/butil/containers/scoped_ptr_hash_map.h
b/src/butil/containers/scoped_ptr_hash_map.h
index a24e8722..d69b96a0 100644
--- a/src/butil/containers/scoped_ptr_hash_map.h
+++ b/src/butil/containers/scoped_ptr_hash_map.h
@@ -78,7 +78,7 @@ class ScopedPtrHashMap {
return scoped_ptr<Value>();
scoped_ptr<Value> ret(it->second);
- it->second = NULL;
+ it->second = nullptr;
return ret.Pass();
}
@@ -109,11 +109,11 @@ class ScopedPtrHashMap {
}
// Returns the element in the hash_map that matches the given key.
- // If no such element exists it returns NULL.
+ // If no such element exists it returns nullptr.
Value* get(const Key& k) const {
const_iterator it = find(k);
if (it == end())
- return NULL;
+ return nullptr;
return it->second;
}
diff --git a/src/butil/containers/small_map.h b/src/butil/containers/small_map.h
index 4b619a11..83ea6f2b 100644
--- a/src/butil/containers/small_map.h
+++ b/src/butil/containers/small_map.h
@@ -229,10 +229,10 @@ class SmallMap {
typedef typename NormalMap::iterator::pointer pointer;
typedef typename NormalMap::iterator::reference reference;
- inline iterator(): array_iter_(NULL) {}
+ inline iterator(): array_iter_(nullptr) {}
inline iterator& operator++() {
- if (array_iter_ != NULL) {
+ if (array_iter_ != nullptr) {
++array_iter_;
} else {
++hash_iter_;
@@ -245,7 +245,7 @@ class SmallMap {
return result;
}
inline iterator& operator--() {
- if (array_iter_ != NULL) {
+ if (array_iter_ != nullptr) {
--array_iter_;
} else {
--hash_iter_;
@@ -258,7 +258,7 @@ class SmallMap {
return result;
}
inline value_type* operator->() const {
- if (array_iter_ != NULL) {
+ if (array_iter_ != nullptr) {
return array_iter_->get();
} else {
return hash_iter_.operator->();
@@ -266,7 +266,7 @@ class SmallMap {
}
inline value_type& operator*() const {
- if (array_iter_ != NULL) {
+ if (array_iter_ != nullptr) {
return *array_iter_->get();
} else {
return *hash_iter_;
@@ -274,10 +274,10 @@ class SmallMap {
}
inline bool operator==(const iterator& other) const {
- if (array_iter_ != NULL) {
+ if (array_iter_ != nullptr) {
return array_iter_ == other.array_iter_;
} else {
- return other.array_iter_ == NULL && hash_iter_ == other.hash_iter_;
+ return other.array_iter_ == nullptr && hash_iter_ == other.hash_iter_;
}
}
@@ -294,7 +294,7 @@ class SmallMap {
inline explicit iterator(ManualConstructor<value_type>* init)
: array_iter_(init) {}
inline explicit iterator(const typename NormalMap::iterator& init)
- : array_iter_(NULL), hash_iter_(init) {}
+ : array_iter_(nullptr), hash_iter_(init) {}
ManualConstructor<value_type>* array_iter_;
typename NormalMap::iterator hash_iter_;
@@ -309,13 +309,13 @@ class SmallMap {
typedef typename NormalMap::const_iterator::pointer pointer;
typedef typename NormalMap::const_iterator::reference reference;
- inline const_iterator(): array_iter_(NULL) {}
+ inline const_iterator(): array_iter_(nullptr) {}
// Non-explicit ctor lets us convert regular iterators to const iterators
inline const_iterator(const iterator& other)
: array_iter_(other.array_iter_), hash_iter_(other.hash_iter_) {}
inline const_iterator& operator++() {
- if (array_iter_ != NULL) {
+ if (array_iter_ != nullptr) {
++array_iter_;
} else {
++hash_iter_;
@@ -329,7 +329,7 @@ class SmallMap {
}
inline const_iterator& operator--() {
- if (array_iter_ != NULL) {
+ if (array_iter_ != nullptr) {
--array_iter_;
} else {
--hash_iter_;
@@ -343,7 +343,7 @@ class SmallMap {
}
inline const value_type* operator->() const {
- if (array_iter_ != NULL) {
+ if (array_iter_ != nullptr) {
return array_iter_->get();
} else {
return hash_iter_.operator->();
@@ -351,7 +351,7 @@ class SmallMap {
}
inline const value_type& operator*() const {
- if (array_iter_ != NULL) {
+ if (array_iter_ != nullptr) {
return *array_iter_->get();
} else {
return *hash_iter_;
@@ -359,10 +359,10 @@ class SmallMap {
}
inline bool operator==(const const_iterator& other) const {
- if (array_iter_ != NULL) {
+ if (array_iter_ != nullptr) {
return array_iter_ == other.array_iter_;
} else {
- return other.array_iter_ == NULL && hash_iter_ == other.hash_iter_;
+ return other.array_iter_ == nullptr && hash_iter_ == other.hash_iter_;
}
}
@@ -377,7 +377,7 @@ class SmallMap {
: array_iter_(init) {}
inline explicit const_iterator(
const typename NormalMap::const_iterator& init)
- : array_iter_(NULL), hash_iter_(init) {}
+ : array_iter_(nullptr), hash_iter_(init) {}
const ManualConstructor<value_type>* array_iter_;
typename NormalMap::const_iterator hash_iter_;
diff --git a/src/butil/containers/stack_container.h
b/src/butil/containers/stack_container.h
index 5679ab86..b7c5d9b0 100644
--- a/src/butil/containers/stack_container.h
+++ b/src/butil/containers/stack_container.h
@@ -93,14 +93,14 @@ class StackAllocator : public std::allocator<T> {
// iff sizeof(T) == sizeof(U).
template<typename U, size_t other_capacity>
StackAllocator(const StackAllocator<U, other_capacity>& other)
- : source_(NULL) {
+ : source_(nullptr) {
}
// This constructor must exist. It creates a default allocator that doesn't
// actually have a stack buffer. glibc's std::string() will compare the
// current allocator against the default-constructed allocator, so this
// should be fast.
- StackAllocator() : source_(NULL) {
+ StackAllocator() : source_(nullptr) {
}
explicit StackAllocator(Source* source) : source_(source) {
@@ -110,7 +110,7 @@ class StackAllocator : public std::allocator<T> {
// and the size requested fits. Otherwise, fall through to the standard
// allocator.
pointer allocate(size_type n, void* hint = 0) {
- if (source_ != NULL && !source_->used_stack_buffer_
+ if (source_ != nullptr && !source_->used_stack_buffer_
&& n <= stack_capacity) {
source_->used_stack_buffer_ = true;
return source_->stack_buffer();
@@ -127,7 +127,7 @@ class StackAllocator : public std::allocator<T> {
// Free: when trying to free the stack buffer, just mark it as free. For
// non-stack-buffer pointers, just fall though to the standard allocator.
void deallocate(pointer p, size_type n) {
- if (source_ != NULL && p == source_->stack_buffer())
+ if (source_ != nullptr && p == source_->stack_buffer())
source_->used_stack_buffer_ = false;
else
std::allocator<T>::deallocate(p, n);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]