Changeset 7413


Ignore:
Timestamp:
2004-05-25T11:00:18+12:00 (20 years ago)
Author:
mdewsnip
Message:

(Human Info) Added a variant of SetCStr that allows you to specify an initial size for the string (for more efficient memory usage).

Location:
trunk/gsdl/src/mgpp/text
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/mgpp/text/UCArray.cpp

    r3008 r7413  
    3030    text.push_back (*cStr);
    3131    cStr++;
     32  }
     33}
     34
     35void SetCStr (UCArray &text, const char *cStr, size_t nSizeHint) {
     36  text.erase(text.begin(), text.end());
     37
     38  // reserve the needed space in advance
     39  if (text.capacity() < nSizeHint + 1) {
     40    text.reserve(nSizeHint + 1);
     41  }
     42  while (*cStr != '\0') {
     43    text.push_back (*cStr);
     44    ++cStr;
    3245  }
    3346}
  • trunk/gsdl/src/mgpp/text/UCArray.h

    r3008 r7413  
    5555// functions to manipulate UCArrays
    5656void SetCStr (UCArray &text, const char *cStr);
     57// same as SetCStr but first tries to allocate nSizeHint space (only if needed)
     58void SetCStr (UCArray &text, const char *cStr, size_t nSizeHint);
    5759char * GetCStr(UCArray text);
    5860inline void UCArrayClear (UCArray &a) {
Note: See TracChangeset for help on using the changeset viewer.