Commit 1f33554a by Paolo Carlini Committed by Paolo Carlini

codecvt_members.cc (do_out): If we can upper bound the total number of external…

codecvt_members.cc (do_out): If we can upper bound the total number of external chars to something smaller...

2003-11-19  Paolo Carlini  <pcarlini@suse.de>

	* config/locale/gnu/codecvt_members.cc (do_out): If
	we can upper bound the total number of external chars
	to something smaller than __to_end - __to, avoid the
	temporary buffer, the memcopy and simplify the loop.
	* config/locale/generic/codecvt_members.cc (do_out):
	Likewise.

From-SVN: r73733
parent edfe1ac7
2003-11-19 Paolo Carlini <pcarlini@suse.de>
* config/locale/gnu/codecvt_members.cc (do_out): If
we can upper bound the total number of external chars
to something smaller than __to_end - __to, avoid the
temporary buffer, the memcopy and simplify the loop.
* config/locale/generic/codecvt_members.cc (do_out):
Likewise.
2003-11-19 Andreas Tobler <a.tobler@schweiz.ch> 2003-11-19 Andreas Tobler <a.tobler@schweiz.ch>
* testsuite/lib/libstdc++.exp: Add DYLD_LIBRARY_PATH for darwin. * testsuite/lib/libstdc++.exp: Add DYLD_LIBRARY_PATH for darwin.
......
...@@ -49,17 +49,35 @@ namespace std ...@@ -49,17 +49,35 @@ namespace std
result __ret = ok; result __ret = ok;
// The conversion must be done using a temporary destination buffer // The conversion must be done using a temporary destination buffer
// since it is not possible to pass the size of the buffer to wcrtomb // since it is not possible to pass the size of the buffer to wcrtomb
extern_type __buf[MB_LEN_MAX];
// A temporary state must be used since the result of the last
// conversion may be thrown away.
state_type __tmp_state(__state); state_type __tmp_state(__state);
// The conversion must be done by calling wcrtomb in a loop rather // The conversion must be done by calling wcrtomb in a loop rather
// than using wcsrtombs because wcsrtombs assumes that the input is // than using wcsrtombs because wcsrtombs assumes that the input is
// zero-terminated. // zero-terminated.
// Either we can upper bound the total number of external characters to
// something smaller than __to_end - __to or the conversion must be done
// using a temporary destination buffer since it is not possible to
// pass the size of the buffer to wcrtomb
if (MB_CUR_MAX * (__from_end - __from) - (__to_end - __to) <= 0)
while (__from < __from_end)
{
const size_t __conv = wcrtomb(__to, *__from, &__tmp_state);
if (__conv == static_cast<size_t>(-1))
{
__ret = error;
break;
}
__state = __tmp_state;
__to += __conv;
__from++;
}
else
{
extern_type __buf[MB_LEN_MAX];
while (__from < __from_end && __to < __to_end) while (__from < __from_end && __to < __to_end)
{ {
size_t __conv = wcrtomb(__buf, *__from, &__tmp_state); const size_t __conv = wcrtomb(__buf, *__from, &__tmp_state);
if (__conv == static_cast<size_t>(-1)) if (__conv == static_cast<size_t>(-1))
{ {
__ret = error; __ret = error;
...@@ -76,6 +94,7 @@ namespace std ...@@ -76,6 +94,7 @@ namespace std
__to += __conv; __to += __conv;
__from++; __from++;
} }
}
if (__ret == ok && __from < __from_end) if (__ret == ok && __from < __from_end)
__ret = partial; __ret = partial;
......
...@@ -48,9 +48,6 @@ namespace std ...@@ -48,9 +48,6 @@ namespace std
extern_type*& __to_next) const extern_type*& __to_next) const
{ {
result __ret = ok; result __ret = ok;
// The conversion must be done using a temporary destination buffer
// since it is not possible to pass the size of the buffer to wcrtomb
extern_type __buf[MB_LEN_MAX];
// A temporary state must be used since the result of the last // A temporary state must be used since the result of the last
// conversion may be thrown away. // conversion may be thrown away.
state_type __tmp_state(__state); state_type __tmp_state(__state);
...@@ -62,9 +59,30 @@ namespace std ...@@ -62,9 +59,30 @@ namespace std
// The conversion must be done by calling wcrtomb in a loop rather // The conversion must be done by calling wcrtomb in a loop rather
// than using wcsrtombs because wcsrtombs assumes that the input is // than using wcsrtombs because wcsrtombs assumes that the input is
// zero-terminated. // zero-terminated.
// Either we can upper bound the total number of external characters to
// something smaller than __to_end - __to or the conversion must be done
// using a temporary destination buffer since it is not possible to
// pass the size of the buffer to wcrtomb
if (MB_CUR_MAX * (__from_end - __from) - (__to_end - __to) <= 0)
while (__from < __from_end)
{
const size_t __conv = wcrtomb(__to, *__from, &__tmp_state);
if (__conv == static_cast<size_t>(-1))
{
__ret = error;
break;
}
__state = __tmp_state;
__to += __conv;
__from++;
}
else
{
extern_type __buf[MB_LEN_MAX];
while (__from < __from_end && __to < __to_end) while (__from < __from_end && __to < __to_end)
{ {
size_t __conv = wcrtomb(__buf, *__from, &__tmp_state); const size_t __conv = wcrtomb(__buf, *__from, &__tmp_state);
if (__conv == static_cast<size_t>(-1)) if (__conv == static_cast<size_t>(-1))
{ {
__ret = error; __ret = error;
...@@ -81,6 +99,7 @@ namespace std ...@@ -81,6 +99,7 @@ namespace std
__to += __conv; __to += __conv;
__from++; __from++;
} }
}
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
__uselocale(__old); __uselocale(__old);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment