summaryrefslogtreecommitdiff
path: root/Zend/zend_alloc.c
diff options
context:
space:
mode:
authorBob Weinand <bobwei9@hotmail.com>2015-09-19 23:07:43 +0200
committerBob Weinand <bobwei9@hotmail.com>2015-09-19 23:07:43 +0200
commit08e253cdbc0a98e160cfd9c810ba213c7bcb3512 (patch)
treeb879eff5cd2bae6cba66d323052d300448ed44b6 /Zend/zend_alloc.c
parentb8f56013b5501071a0fa5c74401afe861e5519f7 (diff)
downloadphp-git-08e253cdbc0a98e160cfd9c810ba213c7bcb3512.tar.gz
Optimize zend_mm_small_size_to_bin()
It removes a cmov operation and has a much faster branch for small allocations (especially when handling strings) (<= 64 bytes)
Diffstat (limited to 'Zend/zend_alloc.c')
-rw-r--r--Zend/zend_alloc.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index bf147f55e5..bd3fe0ebcc 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -1202,17 +1202,19 @@ static zend_always_inline int zend_mm_small_size_to_bin(size_t size)
n = zend_mm_small_size_to_bit(size - 1);
return ((size-1) >> f1[n]) + f2[n];
#else
- int t1, t2, t3;
-
- if (UNEXPECTED(size <= 8)) return 0;
- t1 = (int)(size - 1);
- t2 = zend_mm_small_size_to_bit(t1);
- t3 = t2 - 6;
- t3 = (t3 < 0) ? 0 : t3;
- t2 = t3 + 3;
- t1 = t1 >> t2;
- t3 = t3 << 2;
- return t1 + t3;
+ unsigned int t1, t2;
+
+ if (size <= 64) {
+ /* we need to support size == 0 ... */
+ return (size - !!size) >> 3;
+ } else {
+ t1 = size - 1;
+ t2 = zend_mm_small_size_to_bit(t1) - 3;
+ t1 = t1 >> t2;
+ t2 = t2 - 3;
+ t2 = t2 << 2;
+ return (int)(t1 + t2);
+ }
#endif
}