[PATCH 1/4] msvcp90: Added basic_string<char>::swap implementation. (try 2)

Vincas Miliūnas vincas.miliunas at gmail.com
Mon Nov 15 11:26:44 CST 2010


Based on the feedback ( http://www.winehq.org/pipermail/wine-devel/2010-November/087860.html ), I've removed handling of cases of different allocators, since it's safe to assume they're identical.

Also a minor note:

> +/* Helper function for MSVCP_basic_string_char_swap */
> +void basic_string_char_swap_bufxptr_same_alloc(basic_string_char * lhs, 
> basic_string_char * rhs)
> +{
> +    char * const ptr = rhs->data.ptr;
> +    const size_t size = rhs->size;
> +    const size_t res = rhs->res;
> +
> +    memcpy(rhs->data.buf, lhs->data.buf, lhs->size * sizeof(char));
> This function should work in constant time. It should only swap pointers 
> and lengths.

Well, the codepath when both strings are allocated (this->res > BUF_SIZE_CHAR - 1 && str->res > BUF_SIZE_CHAR - 1) works in constant time. (It can be found in the last lines of MSVCP_basic_string_char_swap function.)

The way I see this is that the code above handles the case when lhs string is in the local buffer and rhs is allocated. The exchange requires copying (lhs->data->buf into rhs->data->buf and rhs->data->ptr into lhs->data->ptr), since setting one's ptr to other's buf would be illegal. Also, the ptr and buf are in an union construct and overlap, therefore only one can be stored at a time.

---
 dlls/msvcp80/msvcp80.spec |    4 +-
 dlls/msvcp90/msvcp90.spec |    4 +-
 dlls/msvcp90/string.c     |   64 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 4 deletions(-)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-msvcp90-Added-basic_string-char-swap-implementation..patch
Type: text/x-patch
Size: 4977 bytes
Desc: not available
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20101115/319f831e/attachment-0001.bin>


More information about the wine-patches mailing list