Commit 5e1c8f73ae98d35de8101477fe64e01403811e4f
1 parent
e905bad9
fix optimization for GNU memory management
Showing
1 changed file
with
10 additions
and
6 deletions
... | ... | @@ -736,7 +736,6 @@ TR_malloc(size_t size) |
736 | 736 | { |
737 | 737 | struct memSegment * seg = NULL; |
738 | 738 | long psize = sysconf(_SC_PAGESIZE); |
739 | - size_t check; | |
740 | 739 | |
741 | 740 | size += sizeof(struct memSegment); |
742 | 741 | |
... | ... | @@ -746,12 +745,17 @@ TR_malloc(size_t size) |
746 | 745 | size = ((size / psize) + 1) * psize; |
747 | 746 | } |
748 | 747 | } else { |
749 | - check = size >> 1; | |
750 | - check = (size | check) - check; | |
748 | + if (size < 8) { | |
749 | + size = 8; | |
750 | + } else { | |
751 | + size_t check = size; | |
752 | + size_t mask = 1; | |
753 | + | |
754 | + while (check >>= 1) { | |
755 | + mask = (mask << 1) | 1; | |
756 | + } | |
751 | 757 | |
752 | - if (check != size) { | |
753 | - // size is not a power of 2 so bring it to one. | |
754 | - size = ((size << 1) | size) - size; | |
758 | + size = (size << 1) & ~mask; | |
755 | 759 | } |
756 | 760 | } |
757 | 761 | ... | ... |
Please
register
or
login
to post a comment