stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: svn commit: r605548 - in /incubator/stdcxx/branches/4.2.x/include: rw/_defs.h rw/_specialized.h sstream string
Date Wed, 19 Dec 2007 16:26:37 GMT
faridz@apache.org wrote:
> Author: faridz
> Date: Wed Dec 19 06:19:33 2007
> New Revision: 605548
> 
> URL: http://svn.apache.org/viewvc?rev=605548&view=rev
> Log:
> 2007-12-19 Farid Zaripov <farid_zaripov@epam.com>
> 
> 	STDCXX-226
> 	* include/rw/_defs.h (_RWSTD_RATIO_DIVIDER): New macro defined the value
> 	to divide the _RWSTD_{NEW|STRING}_CAPACITY_RATIO.
> 	(_RWSTD_NEW_CAPACITY_RATIO): The value with floating point replaced to
> 	integer value using multiplication with _RWSTD_RATIO_DIVIDER.
> 	(_RWSTD_STRING_CAPACITY_RATIO): Ditto.
> 	* include/rw/_specialized.h (__rw_new_capacity): Floating point
> 	operations replaced to integer operations.
> 	* include/sstream (_C_grow): Ditto.
> 	* include/string (__rw_new_capacity): Ditto.
> 
> Modified:
>     incubator/stdcxx/branches/4.2.x/include/rw/_defs.h
>     incubator/stdcxx/branches/4.2.x/include/rw/_specialized.h
>     incubator/stdcxx/branches/4.2.x/include/sstream
>     incubator/stdcxx/branches/4.2.x/include/string
> 
> Modified: incubator/stdcxx/branches/4.2.x/include/rw/_defs.h
> URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/include/rw/_defs.h?rev=605548&r1=605547&r2=605548&view=diff
> ==============================================================================
> --- incubator/stdcxx/branches/4.2.x/include/rw/_defs.h (original)
> +++ incubator/stdcxx/branches/4.2.x/include/rw/_defs.h Wed Dec 19 06:19:33 2007
> @@ -431,19 +431,26 @@
>  // function overloads in the string header.  These are tweakable here
>  // with the STRING version of these macros.
>  //
> +#if !defined (_RWSTD_RATIO_DIVIDER)
> +#  define _RWSTD_RATIO_DIVIDER   1000U
> +#endif
> +
>  #if !defined(_RWSTD_MINIMUM_NEW_CAPACITY)
>  #  define _RWSTD_MINIMUM_NEW_CAPACITY   32U
>  #endif
> +
>  #if !defined(_RWSTD_NEW_CAPACITY_RATIO)
>     // using long doubles to eliminate bogus warnings on g++ 2.95.2/sparc
>     // (-W -O2/3 only): warning: overflow on truncation to integer

The comment above is no longer relevant now that we've switched
to integers and should be removed.

> -#  define _RWSTD_NEW_CAPACITY_RATIO 1.618L
> +#  define _RWSTD_NEW_CAPACITY_RATIO 1618U
>  #endif
> +
>  #if !defined(_RWSTD_MINIMUM_STRING_CAPACITY)
>  #  define _RWSTD_MINIMUM_STRING_CAPACITY   128U
>  #endif
> +
>  #if !defined(_RWSTD_STRING_CAPACITY_RATIO)
> -#  define _RWSTD_STRING_CAPACITY_RATIO 1.618L
> +#  define _RWSTD_STRING_CAPACITY_RATIO 1618U
>  #endif
>  
>  #if !defined (_RWSTD_MINIMUM_STRINGBUF_CAPACITY)
> 
> Modified: incubator/stdcxx/branches/4.2.x/include/rw/_specialized.h
> URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/include/rw/_specialized.h?rev=605548&r1=605547&r2=605548&view=diff
> ==============================================================================
> --- incubator/stdcxx/branches/4.2.x/include/rw/_specialized.h (original)
> +++ incubator/stdcxx/branches/4.2.x/include/rw/_specialized.h Wed Dec 19 06:19:33 2007
> @@ -69,8 +69,12 @@
>  {
>      typedef _RWSTD_CONTAINER_SIZE_TYPE _RWSizeT;
>  
> -    _RWSizeT __cap = _RWSTD_STATIC_CAST (_RWSizeT,
> -                                       __size * _RWSTD_NEW_CAPACITY_RATIO);
> +    const _RWSizeT __ratio = _RWSizeT (  (_RWSTD_NEW_CAPACITY_RATIO << 10)
> +                                       / _RWSTD_RATIO_DIVIDER);

Sorry to bringing this up only now that you've committed it...

Would it make sense to make __ratio a global macro instead of repeating
the same computation in several places? Also, since the divider is used
only in the computation of the ratio and since we're hardcoding the 10
in the left shift, it sees we might as well hardcode the 1000 and forget
the divider.

Martin


> +
> +    const _RWSizeT __cap =   (__size >> 10) * __ratio
> +                           + (((__size & 0x3ff) * __ratio) >> 10);
> +
>      return (__size += _RWSTD_MINIMUM_NEW_CAPACITY) > __cap ? __size : __cap;
>  }                     
>  
> 
> Modified: incubator/stdcxx/branches/4.2.x/include/sstream
> URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/include/sstream?rev=605548&r1=605547&r2=605548&view=diff
> ==============================================================================
> --- incubator/stdcxx/branches/4.2.x/include/sstream (original)
> +++ incubator/stdcxx/branches/4.2.x/include/sstream Wed Dec 19 06:19:33 2007
> @@ -207,11 +207,15 @@
>  basic_stringbuf<_CharT, _Traits, _Allocator>::
>  _C_grow (_RWSTD_STREAMSIZE __to) const
>  {
> +    const _RWSTD_STREAMSIZE __ratio =
> +        _RWSTD_STREAMSIZE (  (_RWSTD_NEW_CAPACITY_RATIO << 10)
> +                           / _RWSTD_RATIO_DIVIDER);
> +
>      const _RWSTD_STREAMSIZE __cap =
> -        _RWSTD_STATIC_CAST (_RWSTD_STREAMSIZE,
> -                            this->_C_bufsize ?
> -                            this->_C_bufsize * _RWSTD_NEW_CAPACITY_RATIO
> -                            : _RWSTD_MINIMUM_STRINGBUF_CAPACITY);
> +        this->_C_bufsize ?
> +          (this->_C_bufsize >> 10) * __ratio
> +        + (((this->_C_bufsize & 0x3ff) * __ratio) >> 10)
> +        : _RWSTD_MINIMUM_STRINGBUF_CAPACITY;
>  
>      return __cap < __to ? __to : __cap;
>  }
> 
> Modified: incubator/stdcxx/branches/4.2.x/include/string
> URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/include/string?rev=605548&r1=605547&r2=605548&view=diff
> ==============================================================================
> --- incubator/stdcxx/branches/4.2.x/include/string (original)
> +++ incubator/stdcxx/branches/4.2.x/include/string Wed Dec 19 06:19:33 2007
> @@ -1535,8 +1535,12 @@
>  {
>      typedef _RWSTD_STRING_SIZE_TYPE _RWSizeT;
>  
> -    _RWSizeT __cap = 
> -        _RWSTD_STATIC_CAST (_RWSizeT, __size * _RWSTD_STRING_CAPACITY_RATIO);
> +    const _RWSizeT __ratio = _RWSizeT (  (_RWSTD_STRING_CAPACITY_RATIO << 10)
> +                                       / _RWSTD_RATIO_DIVIDER);
> +
> +    const _RWSizeT __cap =   (__size >> 10) * __ratio
> +                           + (((__size & 0x3ff) * __ratio) >> 10);
> +
>      return (__size += _RWSTD_MINIMUM_STRING_CAPACITY) > __cap ? __size : __cap;
>  }                     
>  
> @@ -1557,9 +1561,14 @@
>  __rw_new_capacity (_RWSTD_STRING_SIZE_TYPE (_STD::string) __size,
>                     const _STD::string*)
>  {
> -    _RWSTD_STRING_SIZE_TYPE (_STD::string) __cap = 
> -        _RWSTD_STATIC_CAST (_RWSTD_STRING_SIZE_TYPE (_STD::string),
> -                            __size * _RWSTD_STRING_CAPACITY_RATIO);
> +    typedef _RWSTD_STRING_SIZE_TYPE (_STD::string) _RWSizeT;
> +
> +    const _RWSizeT __ratio = _RWSizeT (  (_RWSTD_STRING_CAPACITY_RATIO << 10)
> +                                       / _RWSTD_RATIO_DIVIDER);
> +
> +    const _RWSizeT __cap =   (__size >> 10) * __ratio
> +                           + (((__size & 0x3ff) * __ratio) >> 10);
> +
>      return (__size += _RWSTD_MINIMUM_STRING_CAPACITY) > __cap ? __size : __cap;
>  }                     
>  
> @@ -1568,9 +1577,14 @@
>  __rw_new_capacity (_RWSTD_STRING_SIZE_TYPE (_STD::wstring) __size,
>                     const _STD::wstring*)
>  {
> -    _RWSTD_STRING_SIZE_TYPE (_STD::wstring) __cap = 
> -        _RWSTD_STATIC_CAST (_RWSTD_STRING_SIZE_TYPE (_STD::wstring),
> -                            __size * _RWSTD_STRING_CAPACITY_RATIO);
> +    typedef _RWSTD_STRING_SIZE_TYPE (_STD::wstring) _RWSizeT;
> +
> +    const _RWSizeT __ratio = _RWSizeT (  (_RWSTD_STRING_CAPACITY_RATIO << 10)
> +                                       / _RWSTD_RATIO_DIVIDER);
> +
> +    const _RWSizeT __cap =   (__size >> 10) * __ratio
> +                           + (((__size & 0x3ff) * __ratio) >> 10);
> +
>      return (__size += _RWSTD_MINIMUM_STRING_CAPACITY) > __cap  ? __size : __cap;
>  }                     
>  
> 
> 
> 


Mime
View raw message