This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH to bits/demangle.h


Benjamin,

assuming that nothing else (hidden) calls operator new/delete, then
the following patch might make sense: it removes the sole instance
where new/delete are called and also uses the Allocator that is
being passed in that case.

What do you think, can I apply it?

Tested on 3.4 branch (bootstrap + testsuite).


* 2004-02-24  Carlo Wood  <carlo@alinoe.com>

* bits/demangle.h
namespace __gnu_cxx::demangler
(session<Allocator>::qualifier_list_Allocator): Add
(session<Allocator>::M_qualifier_list_alloc): Add
(session<Allocator>::decode_type_with_postfix):
Use M_qualifier_list_alloc instead of calling operator new/delete.

Index: include/bits/demangle.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/demangle.h,v
retrieving revision 1.16
diff -u -d -p -r1.16 demangle.h
--- include/bits/demangle.h	19 Dec 2003 23:15:24 -0000	1.16
+++ include/bits/demangle.h	24 Feb 2004 19:20:31 -0000
@@ -378,6 +378,9 @@ namespace __gnu_cxx
 	int M_template_arg_pos_offset;
 	std::vector<substitution_st, subst_Allocator> M_substitutions_pos;
 	implementation_details const& M_implementation_details;
+	typedef typename Allocator::template
+	    rebind<qualifier_list<Allocator> >::other qualifier_list_Allocator;
+	qualifier_list_Allocator M_qualifier_list_alloc;
 #if _GLIBCXX_DEMANGLER_CWDEBUG
 	bool M_inside_add_substitution;
 #endif
@@ -1849,7 +1852,10 @@ namespace __gnu_cxx
 	++M_inside_type;
 	bool recursive_template_param_or_substitution_call;
 	if (!(recursive_template_param_or_substitution_call = qualifiers))
-	    qualifiers = new qualifier_list<Allocator>(*this);
+	{
+          qualifier_list<Allocator>* raw_qualifiers = M_qualifier_list_alloc.allocate(1);
+	  qualifiers = new (raw_qualifiers) qualifier_list<Allocator>(*this);
+	}
 	// First eat all qualifiers.
 	bool failure = false;
 	for(;;)		// So we can use 'continue' to eat the next qualifier.
@@ -2181,7 +2187,10 @@ namespace __gnu_cxx
     decode_type_exit:
 	--M_inside_type;
 	if (!recursive_template_param_or_substitution_call)
-	  delete qualifiers;
+	{
+	  qualifiers->~qualifier_list<Allocator>();
+	  M_qualifier_list_alloc.deallocate(qualifiers, 1);
+	}
 	if (failure)
 	  _GLIBCXX_DEMANGLER_FAILURE;
 	_GLIBCXX_DEMANGLER_RETURN2;

-- 
Carlo Wood <carlo@alinoe.com>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]