mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-10 21:41:14 +08:00
basic_string.tcc (_S_create): Use consistently the exponential policy, simplify.
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). From-SVN: r88972
This commit is contained in:
parent
f76ccf602e
commit
cbb0dcef12
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user