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] Tiny (but cool ;) change to bitset::_M_copy_from_string


Hi,

today, prompted by Zdenek loop reversal patch, was re-checking that the
recent (by hand) loop reversal in bitset was not worsening the code
(indeed, everything is fine, even slightly better than 4_1) and noticed
this funny thing: in _M_copy_from_string (inconsistently with
_M_copy_to_string) we are calling the general bitset::set(size_t, bool),
instead of the internal, unchecked, _Unchecked_set.

That means two completely redundant conditionals (one for out of range;
one for set vs reset basing on the second argument) and, for this stupid
snippet, for example:

  string s(10000, '1');
  for (unsigned i = 0; i < 100000; ++i)
    bitset<10000> bs(s);

On an x86-linux, P4-2400, -O2:

Current mainline
----------------
4.696u 0.004s 0:04.69 100.0%    0+0k 0+0io 0pf+0w

Current mainline + patch
------------------------
3.848u 0.000s 0:03.84 100.0%    0+0k 0+0io 0pf+0w


Too cool? ;) Seriously, I cannot imagine anything wrong with the change,
but please have a close look...

Tested x86-linux.

Paolo.

///////////////
2006-01-26  Paolo Carlini  <pcarlini@suse.de>

	* include/std/std_bitset.h (bitset<>::_M_copy_to_string):
	Call the internal _Unchecked_set(size_t) instead of set.
Index: include/std/std_bitset.h
===================================================================
--- include/std/std_bitset.h	(revision 110251)
+++ include/std/std_bitset.h	(working copy)
@@ -1,6 +1,7 @@
 // <bitset> -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+// 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
@@ -1157,7 +1158,7 @@
 	      case '0':
 		break;
 	      case '1':
-		set(__i - 1);
+		_Unchecked_set(__i - 1);
 		break;
 	      default:
 		__throw_invalid_argument(__N("bitset::_M_copy_from_string"));

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