mirror of
https://github.com/gperftools/gperftools
synced 2024-12-23 15:52:10 +00:00
added SizeMap::MaybeSizeClass
Because it allows us to first check for smaller sizes, which is most likely.
This commit is contained in:
parent
436e1dea43
commit
10f7e20716
29
src/common.h
29
src/common.h
@ -194,15 +194,23 @@ class SizeMap {
|
||||
((kMaxSize + 127 + (120 << 7)) >> 7) + 1;
|
||||
unsigned char class_array_[kClassArraySize];
|
||||
|
||||
static inline size_t SmallSizeClass(size_t s) {
|
||||
return (static_cast<uint32_t>(s) + 7) >> 3;
|
||||
}
|
||||
|
||||
static inline size_t LargeSizeClass(size_t s) {
|
||||
return (static_cast<uint32_t>(s) + 127 + (120 << 7)) >> 7;
|
||||
}
|
||||
|
||||
// Compute index of the class_array[] entry for a given size
|
||||
static inline size_t ClassIndex(int s) {
|
||||
static inline size_t ClassIndex(size_t s) {
|
||||
// Use unsigned arithmetic to avoid unnecessary sign extensions.
|
||||
ASSERT(0 <= s);
|
||||
ASSERT(s <= kMaxSize);
|
||||
if (LIKELY(s <= kMaxSmallSize)) {
|
||||
return (static_cast<uint32_t>(s) + 7) >> 3;
|
||||
return SmallSizeClass(s);
|
||||
} else {
|
||||
return (static_cast<uint32_t>(s) + 127 + (120 << 7)) >> 7;
|
||||
return LargeSizeClass(s);
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,10 +230,23 @@ class SizeMap {
|
||||
// Initialize the mapping arrays
|
||||
void Init();
|
||||
|
||||
inline int SizeClass(int size) {
|
||||
inline int SizeClass(size_t size) {
|
||||
return class_array_[ClassIndex(size)];
|
||||
}
|
||||
|
||||
inline bool MaybeSizeClass(size_t size, size_t *size_class) {
|
||||
size_t class_idx;
|
||||
if (LIKELY(size <= kMaxSmallSize)) {
|
||||
class_idx = SmallSizeClass(size);
|
||||
} else if (size <= kMaxSize) {
|
||||
class_idx = LargeSizeClass(size);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
*size_class = class_array_[class_idx];
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the byte-size for a specified class
|
||||
inline size_t ByteSizeForClass(size_t cl) {
|
||||
return class_to_size_[cl];
|
||||
|
Loading…
Reference in New Issue
Block a user