diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-10-13 08:58:41 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-10-13 08:58:41 +0000 |
commit | 391e9e03ddd2f26d92bc51fd9633406fb83d97c1 (patch) | |
tree | 0c82b01d7007405dc4ce129bb2cea24575ff00a3 /libstdc++-v3 | |
parent | 56ff961b25c723dc51b7a93b1f610780a83ba3d1 (diff) | |
download | ppe42-gcc-391e9e03ddd2f26d92bc51fd9633406fb83d97c1.tar.gz ppe42-gcc-391e9e03ddd2f26d92bc51fd9633406fb83d97c1.zip |
2004-10-13 Paolo Carlini <pcarlini@suse.de>
* include/bits/basic_string.tcc (_S_create): Use consistently
the exponential policy, simplify.
* testsuite/performance/21_strings/string_append_2.cc: New.
* include/ext/array_allocator.h (allocate): Fix bad_alloc check.
* testsuite/ext/array_allocator/2.cc: Fix wrt 64-bit archs (in
that case sizeof(_Rep) == 24).
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@88972 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 10 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.tcc | 20 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/array_allocator.h | 8 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/ext/array_allocator/2.cc | 2 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/performance/21_strings/string_append_2.cc | 55 |
5 files changed, 73 insertions, 22 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7a11af91efb..fb324114889 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2004-10-13 Paolo Carlini <pcarlini@suse.de> + + * include/bits/basic_string.tcc (_S_create): Use consistently + the exponential policy, simplify. + * testsuite/performance/21_strings/string_append_2.cc: New. + + * include/ext/array_allocator.h (allocate): Fix bad_alloc check. + * testsuite/ext/array_allocator/2.cc: Fix wrt 64-bit archs (in + that case sizeof(_Rep) == 24). + 2004-10-12 Paolo Carlini <pcarlini@suse.de> PR libstdc++/17948 diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 49b6362e790..66eb982b538 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -503,9 +503,8 @@ namespace std // low-balling it (especially when this algorithm is used with // malloc implementations that allocate memory blocks rounded up // to a size which is a power of 2). - const size_type __pagesize = 4096; // must be 2^i * __subpagesize - const size_type __subpagesize = 128; // should be >> __malloc_header_size - const size_type __malloc_header_size = 4 * sizeof (void*); + const size_type __pagesize = 4096; + const size_type __malloc_header_size = 4 * sizeof(void*); // The below implements an exponential growth policy, necessary to // meet amortized linear time requirements of the library: see @@ -513,14 +512,7 @@ namespace std // It's active for allocations requiring an amount of memory above // system pagesize. This is consistent with the requirements of the // standard: http://gcc.gnu.org/ml/libstdc++/2001-07/msg00130.html - - // The biggest string which fits in a memory page - const size_type __page_capacity = ((__pagesize - __malloc_header_size - - sizeof(_Rep) - sizeof(_CharT)) - / sizeof(_CharT)); - - if (__capacity > __old_capacity && __capacity < 2 * __old_capacity - && __capacity > __page_capacity) + if (__capacity > __old_capacity && __capacity < 2 * __old_capacity) __capacity = 2 * __old_capacity; // NB: Need an array of char_type[__capacity], plus a terminating @@ -538,12 +530,6 @@ namespace std __capacity = _S_max_size; __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep); } - else if (__size > __subpagesize) - { - const size_type __extra = __subpagesize - __adj_size % __subpagesize; - __capacity += __extra / sizeof(_CharT); - __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep); - } // NB: Might throw, but no worries about a leak, mate: _Rep() // does not throw. diff --git a/libstdc++-v3/include/ext/array_allocator.h b/libstdc++-v3/include/ext/array_allocator.h index 22564c821d9..66aa903e154 100644 --- a/libstdc++-v3/include/ext/array_allocator.h +++ b/libstdc++-v3/include/ext/array_allocator.h @@ -116,11 +116,11 @@ namespace __gnu_cxx pointer allocate(size_type __n, const void* = 0) { - static size_type used; - if (__builtin_expect(used > array_type::_S_index, false)) + static size_type __used; + if (__builtin_expect(__used + __n > array_type::_S_index, false)) throw std::bad_alloc(); - pointer __ret = _M_array->begin() + used; - used += __n; + pointer __ret = _M_array->begin() + __used; + __used += __n; return __ret; } }; diff --git a/libstdc++-v3/testsuite/ext/array_allocator/2.cc b/libstdc++-v3/testsuite/ext/array_allocator/2.cc index 2d757b533aa..9ee2d07d554 100644 --- a/libstdc++-v3/testsuite/ext/array_allocator/2.cc +++ b/libstdc++-v3/testsuite/ext/array_allocator/2.cc @@ -32,7 +32,7 @@ typedef char char_type; typedef std::char_traits<char_type> traits_type; -typedef std::tr1::array<char_type, 17> array_type; +typedef std::tr1::array<char_type, 32> array_type; array_type extern_array; diff --git a/libstdc++-v3/testsuite/performance/21_strings/string_append_2.cc b/libstdc++-v3/testsuite/performance/21_strings/string_append_2.cc new file mode 100644 index 00000000000..35cb583d405 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/21_strings/string_append_2.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include <string> +#include <testsuite_performance.h> + +// Short strings didn't grow quickly... +void test01() +{ + using namespace __gnu_test; + time_counter time; + resource_counter resource; + + start_counters(time, resource); + for (unsigned i = 0; i < 200000; ++i) + { + std::string a; + for (unsigned j = 0; j < 400; ++j) + a.append(1, 'x'); + } + stop_counters(time, resource); + + report_performance(__FILE__, "", time, resource); + clear_counters(time, resource); +} + +int main() +{ + test01(); + return 0; +} |