VirtualBox

Changeset 16384 in vbox


Ignore:
Timestamp:
Jan 29, 2009 6:16:07 PM (16 years ago)
Author:
vboxsync
Message:

string.cpp: enable optimization

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/string.h

    r16369 r16384  
    126126
    127127    /**
    128      *  Allocates memory for a string capable to store \a aSize - 1 characters
    129      *  plus the terminating zero character. If \a aSize is zero, or if a
    130      *  memory allocation error occurs, this object will become null.
     128     *  Allocates memory for a string capable to store \a aSize - 1 characters;
     129     *  in other words, aSize includes the terminating zero character. If \a aSize
     130     *  is zero, or if a memory allocation error occurs, this object will become null.
    131131     */
    132132    Bstr &alloc (size_t aSize)
     
    389389
    390390    /**
    391      *  Allocates memory for a string capable to store \a aSize - 1 characters
    392      *  plus the terminating zero character. If \a aSize is zero, or if a
    393      *  memory allocation error occurs, this object will become null.
     391     *  Allocates memory for a string capable to store \a aSize - 1 bytes (not characters!);
     392     *  in other words, aSize includes the terminating zero character. If \a aSize
     393     *  is zero, or if a memory allocation error occurs, this object will become null.
    394394     */
    395395    Utf8Str &alloc (size_t aSize)
  • trunk/src/VBox/Main/glue/string.cpp

    r16378 r16384  
    6868                        return ret;     // return empty string on bad encoding
    6969
    70                 size_t len = psz - pFirst;
    71 #if 1
    72                 char *psz = (char*)RTMemAlloc(len + 1);
    73                 memcpy(psz, pFirst, len);
    74                 psz[len] = '\0';
    75                 ret = psz;
    76                 RTMemFree(psz);
    77 #else /* A proposal that saves a memcpy and alloc/free: */
    78                 ret.alloc(len + 1);
    79                 memcpy(ret.str, pFirst, len);
    80                 ret.str[len] = '\0';
    81 #endif
     70                size_t cbCopy = psz - pFirst;
     71                ret.alloc(cbCopy + 1);
     72                memcpy(ret.str, pFirst, cbCopy);
     73                ret.str[cbCopy] = '\0';
    8274            }
    8375        }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette