Skip to content

Commit

Permalink
Drop "using namespace" in base/allocator
Browse files Browse the repository at this point in the history
The code style guide does not allow "using namespace" and they
have a tendency to cause problems with jumbo builds. This patch
removes a "using namespace" in base.

Change-Id: I6b97574d6348e1b8df537708e99d89b97d6fc75e
Reviewed-on: https://chromium-review.googlesource.com/c/1443018
Reviewed-by: Primiano Tucci <primiano@chromium.org>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#627356}
  • Loading branch information
bratell-at-opera authored and Commit Bot committed Jan 30, 2019
1 parent b947851 commit b00ad78
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions base/allocator/allocator_shim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@

namespace {

using namespace base;

subtle::AtomicWord g_chain_head = reinterpret_cast<subtle::AtomicWord>(
&allocator::AllocatorDispatch::default_dispatch);
base::subtle::AtomicWord g_chain_head =
reinterpret_cast<base::subtle::AtomicWord>(
&base::allocator::AllocatorDispatch::default_dispatch);

bool g_call_new_handler_on_malloc_failure = false;

Expand All @@ -65,15 +64,15 @@ bool CallNewHandler(size_t size) {
#endif
}

inline const allocator::AllocatorDispatch* GetChainHead() {
inline const base::allocator::AllocatorDispatch* GetChainHead() {
// TODO(primiano): Just use NoBarrier_Load once crbug.com/593344 is fixed.
// Unfortunately due to that bug NoBarrier_Load() is mistakenly fully
// barriered on Linux+Clang, and that causes visible perf regressons.
return reinterpret_cast<const allocator::AllocatorDispatch*>(
return reinterpret_cast<const base::allocator::AllocatorDispatch*>(
#if defined(OS_LINUX) && defined(__clang__)
*static_cast<const volatile subtle::AtomicWord*>(&g_chain_head)
*static_cast<const volatile base::subtle::AtomicWord*>(&g_chain_head)
#else
subtle::NoBarrier_Load(&g_chain_head)
base::subtle::NoBarrier_Load(&g_chain_head)
#endif
);
}
Expand Down Expand Up @@ -150,7 +149,7 @@ extern "C" {
// - Assume it did succeed if it returns, in which case reattempt the alloc.

ALWAYS_INLINE void* ShimCppNew(size_t size) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr;
do {
void* context = nullptr;
Expand All @@ -163,7 +162,7 @@ ALWAYS_INLINE void* ShimCppNew(size_t size) {
}

ALWAYS_INLINE void* ShimCppAlignedNew(size_t size, size_t alignment) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr;
do {
void* context = nullptr;
Expand All @@ -181,12 +180,12 @@ ALWAYS_INLINE void ShimCppDelete(void* address) {
#if defined(OS_MACOSX)
context = malloc_default_zone();
#endif
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
return chain_head->free_function(chain_head, address, context);
}

ALWAYS_INLINE void* ShimMalloc(size_t size, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr;
do {
ptr = chain_head->alloc_function(chain_head, size, context);
Expand All @@ -196,7 +195,7 @@ ALWAYS_INLINE void* ShimMalloc(size_t size, void* context) {
}

ALWAYS_INLINE void* ShimCalloc(size_t n, size_t size, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr;
do {
ptr = chain_head->alloc_zero_initialized_function(chain_head, n, size,
Expand All @@ -209,7 +208,7 @@ ALWAYS_INLINE void* ShimCalloc(size_t n, size_t size, void* context) {
ALWAYS_INLINE void* ShimRealloc(void* address, size_t size, void* context) {
// realloc(size == 0) means free() and might return a nullptr. We should
// not call the std::new_handler in that case, though.
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr;
do {
ptr = chain_head->realloc_function(chain_head, address, size, context);
Expand All @@ -219,7 +218,7 @@ ALWAYS_INLINE void* ShimRealloc(void* address, size_t size, void* context) {
}

ALWAYS_INLINE void* ShimMemalign(size_t alignment, size_t size, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr;
do {
ptr = chain_head->alloc_aligned_function(chain_head, alignment, size,
Expand Down Expand Up @@ -258,12 +257,12 @@ ALWAYS_INLINE void* ShimPvalloc(size_t size) {
}

ALWAYS_INLINE void ShimFree(void* address, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
return chain_head->free_function(chain_head, address, context);
}

ALWAYS_INLINE size_t ShimGetSizeEstimate(const void* address, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
return chain_head->get_size_estimate_function(
chain_head, const_cast<void*>(address), context);
}
Expand All @@ -272,29 +271,29 @@ ALWAYS_INLINE unsigned ShimBatchMalloc(size_t size,
void** results,
unsigned num_requested,
void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
return chain_head->batch_malloc_function(chain_head, size, results,
num_requested, context);
}

ALWAYS_INLINE void ShimBatchFree(void** to_be_freed,
unsigned num_to_be_freed,
void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
return chain_head->batch_free_function(chain_head, to_be_freed,
num_to_be_freed, context);
}

ALWAYS_INLINE void ShimFreeDefiniteSize(void* ptr, size_t size, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
return chain_head->free_definite_size_function(chain_head, ptr, size,
context);
}

ALWAYS_INLINE void* ShimAlignedMalloc(size_t size,
size_t alignment,
void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr = nullptr;
do {
ptr = chain_head->aligned_malloc_function(chain_head, size, alignment,
Expand All @@ -310,7 +309,7 @@ ALWAYS_INLINE void* ShimAlignedRealloc(void* address,
void* context) {
// _aligned_realloc(size == 0) means _aligned_free() and might return a
// nullptr. We should not call the std::new_handler in that case, though.
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr = nullptr;
do {
ptr = chain_head->aligned_realloc_function(chain_head, address, size,
Expand All @@ -321,7 +320,7 @@ ALWAYS_INLINE void* ShimAlignedRealloc(void* address,
}

ALWAYS_INLINE void ShimAlignedFree(void* address, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
const base::allocator::AllocatorDispatch* const chain_head = GetChainHead();
return chain_head->aligned_free_function(chain_head, address, context);
}

Expand Down

0 comments on commit b00ad78

Please sign in to comment.