patch: basic_string.tcc

Dhruv Matani dhruvbird@gmx.net
Tue Jul 20 10:32:00 GMT 2004


Hi,
	This patch is basically an optimization for string::rfind(), and
string::find_first_of(). It attempts to use different algorithms for
either functions to speed up the operations of the functions in various
situations. What I have done for find_first_of() is that there is a
threshold(Paolo pointed out that the function will perform badly when
the string passed as a parameter is >> *this, or when the string is too
large, and the table build-up time is >> the normal case) of 128. Only
if the string passed is <= 128 then will the optimized algorithm kick
in. Else, the normal algorithm will be used.

Also, I have one doubt: There is a line such as this:

if (sizeof(char) <= 8 && (some other run-time condition))
{

}
else
{

}

Now, suppose that sizeof(char) > 8, will the optimizer eliminate the if
block completely?

Also, attached are test-cases used for measuring the timing of either of
the functions before and after applying the patch. The file output.txt
contains the timings reported by the above 2 tests before and after the
application of the patch.

Tested x86-Linux.

However, these 2 seemingly unrelated tests are failing on the current
cvs version:

FAIL: 21_strings/basic_string/inserters_extractors/pod/10081-in.cc (test
for excess errors)
WARNING: 21_strings/basic_string/inserters_extractors/pod/10081-in.cc
compilation failed to produce executable
FAIL: 21_strings/basic_string/inserters_extractors/pod/10081-out.cc
(test for excess errors)
WARNING: 21_strings/basic_string/inserters_extractors/pod/10081-out.cc
compilation failed to produce executable




-- 
	-Dhruv Matani.
http://www.geocities.com/dhruvbird/

template<typename Signature>
  class CustomSignature : public Signature
{ };

-------------- next part --------------
2004-07-20  Dhruv Matani  <dhruvbird@gmx.net>
	
	* include/bits/basic_string.tcc: basic_string<>::rfind() ->
	Re-wrote.
	basic_string<>::find_first_of() -> Re-wrote.
	
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.basic_string.tcc.dhruv.20072004
Type: text/x-patch
Size: 3759 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20040720/950f81f3/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rfind_torture.cpp
Type: text/x-c++
Size: 2137 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20040720/950f81f3/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ffirst_of_test.cpp
Type: text/x-c++
Size: 1801 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20040720/950f81f3/attachment-0002.bin>


More information about the Libstdc++ mailing list