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

Piotr Caban piotr.caban at gmail.com
Sun Nov 14 18:26:28 CST 2010


On 11/11/10 18:55, Vincas Miliūnas wrote:
> This implementation handles cases when basic_strings are allocated using different allocators, however WINE's implementation seems to ignore allocators.
It's not ignoring allocators (but it's not setting allocator field). 
There's no legal way of accessing it by end user, so there's no point of 
setting it, unless it's needed internally (and it's not needed for 
correct implementation of basic_string_char_swap function).

+/* 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.

+/* Helper function for MSVCP_basic_string_char_swap */
+MSVCP_BOOL basic_string_char_swap_bufxptr_diff_alloc(basic_string_char 
* lhs, basic_string_char * rhs)
+{
+    char tmp[BUF_SIZE_CHAR];
+    const size_t size = lhs->size;
+    const size_t res = lhs->res;
+    memcpy(tmp, lhs->data.buf, lhs->size * sizeof(char));
+
+    char * const ptr = MSVCP_allocator_char_allocate(lhs->allocator, 
rhs->res);
You can't pass unknown data to MSVCP_allocator_char_allocate, this is 
the implementation of default char allocator. When other allocators are 
in use compiler will use templates.

The function you're implementing is only used when two basic_string_char 
are swapped, because there's no legal way of modifying allocator field 
there's only one case - the same allocators are used.

Cheers,
Piotr



More information about the wine-devel mailing list