diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2006-03-15 15:22:00 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2006-03-15 15:22:00 +0000 |
commit | c95ae50506d66315810e6b1501aa7f4eaee3018e (patch) | |
tree | 82c050368f94054f9b6b3a03982a9567f6aad337 /cpp/src/Ice/Buffer.cpp | |
parent | Fixed removeAdapter to not throw, bug 865 (diff) | |
download | ice-c95ae50506d66315810e6b1501aa7f4eaee3018e.tar.bz2 ice-c95ae50506d66315810e6b1501aa7f4eaee3018e.tar.xz ice-c95ae50506d66315810e6b1501aa7f4eaee3018e.zip |
Performance improvements, mainly inlining
Diffstat (limited to 'cpp/src/Ice/Buffer.cpp')
-rw-r--r-- | cpp/src/Ice/Buffer.cpp | 91 |
1 files changed, 55 insertions, 36 deletions
diff --git a/cpp/src/Ice/Buffer.cpp b/cpp/src/Ice/Buffer.cpp index 6f8374d1e31..a841d822422 100644 --- a/cpp/src/Ice/Buffer.cpp +++ b/cpp/src/Ice/Buffer.cpp @@ -37,7 +37,7 @@ IceInternal::Buffer::Container::swap(Container& other) { if(other._buf == other._fixed) { - value_type tmp[_fixedSize]; + value_type tmp[ICE_BUFFER_FIXED_SIZE]; memcpy(tmp, _fixed, _size); memcpy(_fixed, other._fixed, other._size); memcpy(other._fixed, tmp, _size); @@ -68,51 +68,70 @@ IceInternal::Buffer::Container::swap(Container& other) std::swap(_size, other._size); std::swap(_capacity, other._capacity); + std::swap(_shrinkCounter, other._shrinkCounter); } void -IceInternal::Buffer::Container::resize(size_type n) +IceInternal::Buffer::Container::clear() { - if(n == 0) +#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION + if(_buf != _fixed) { - clear(); + free(_buf); + _buf = _fixed; + } + _size = 0; + _capacity = ICE_BUFFER_FIXED_SIZE; +#else + free(_buf); + _buf = 0; + _size = 0; + _capacity = 0; +#endif +} + +void +IceInternal::Buffer::Container::reserve(size_type n) +{ + if(n > _capacity) + { + _capacity = std::max<size_type>(n, 2 * _capacity); + _capacity = std::max<size_type>(static_cast<size_type>(240), _capacity); + } + else if(n < _capacity) + { + _capacity = n; } else { - if(n > _capacity) - { - _capacity = std::max<size_type>(n, 2 * _capacity); - _capacity = std::max<size_type>(static_cast<size_type>(240), _capacity); - + return; + } + #ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION - if(_buf != _fixed) - { - _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity)); - } - else - { - _buf = reinterpret_cast<pointer>(malloc(_capacity)); - memcpy(_buf, _fixed, _size); - } + if(_buf != _fixed) + { + _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity)); + } + else if(_capacity > ICE_BUFFER_FIXED_SIZE) + { + _buf = reinterpret_cast<pointer>(malloc(_capacity)); + memcpy(_buf, _fixed, _size); + } #else - if(_buf) - { - _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity)); - } - else - { - _buf = reinterpret_cast<pointer>(malloc(_capacity)); - } + if(_buf) + { + _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity)); + } + else + { + _buf = reinterpret_cast<pointer>(malloc(_capacity)); + } #endif - - if(!_buf) - { - SyscallException ex(__FILE__, __LINE__); - ex.error = getSystemErrno(); - throw ex; - } - } - - _size = n; + + if(!_buf) + { + SyscallException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + throw ex; } } |