Changeset 104 for cpp/gdk/sstring.cpp
- Timestamp:
- 07/23/13 18:15:30 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/gdk/sstring.cpp
r92 r104 7 7 #include "nonstd_stl.h" 8 8 #include "extvalue.h" 9 10 #ifdef MULTITHREADED 11 #include <pthread.h> 12 static pthread_mutex_t sstring_ref_lock; 13 #define REF_LOCK pthread_mutex_lock(&sstring_ref_lock); 14 #define REF_UNLOCK pthread_mutex_unlock(&sstring_ref_lock) 15 #else 16 #define REF_LOCK 17 #define REF_UNLOCK 18 #endif 9 19 10 20 static int guessMemSize(int request, int memhint) … … 96 106 SString::~SString() 97 107 { 108 REF_LOCK; 98 109 detach(); 110 REF_UNLOCK; 99 111 } 100 112 … … 102 114 { 103 115 buf=new SBuf(x); 116 memhint=-1; 104 117 } 105 118 … … 113 126 SString::SString(const SString &from) 114 127 { 115 buf=from.buf; 116 if (buf->size) buf->refcount++; 128 if (from.buf==&SBuf::empty()) 129 buf=&SBuf::empty(); 130 else 131 { 132 REF_LOCK; 133 buf=from.buf; 134 if (buf->size) 135 buf->refcount++; 136 REF_UNLOCK; 137 } 117 138 memhint=-1; 118 139 } … … 163 184 { 164 185 if (ensuresize<0) ensuresize=len(); 186 REF_LOCK; 165 187 detachCopy(ensuresize); 188 REF_UNLOCK; 166 189 appending=buf->used; 167 190 return buf->txt; … … 176 199 char *SString::directAppend(int maxappend) 177 200 { 201 REF_LOCK; 178 202 detachCopy(buf->used+maxappend); 203 REF_UNLOCK; 179 204 appending=buf->used; 180 205 return buf->txt+appending; … … 208 233 { 209 234 if (!count) return; 235 REF_LOCK; 210 236 detachCopy(buf->used+count); 237 REF_UNLOCK; 211 238 buf->append(txt,count); 212 239 } … … 230 257 if (!ch) chlen=0; 231 258 else if (chlen<0) chlen=strlen(ch); 259 REF_LOCK; 232 260 detachEmpty(chlen); 261 REF_UNLOCK; 233 262 memcpy(buf->txt,ch,chlen); 234 263 buf->txt[chlen]=0; buf->used=chlen; … … 243 272 { 244 273 if (s.buf==buf) return; 274 REF_LOCK; 245 275 detach(); 246 276 buf=s.buf; 247 277 if (buf->size) buf->refcount++; 278 REF_UNLOCK; 248 279 } 249 280 /////////////////////////////////////// … … 306 337 } 307 338 308 const SString&SString::valueOf(int i)309 { 310 staticSString t;339 SString SString::valueOf(int i) 340 { 341 SString t; 311 342 sprintf(t.directWrite(20),"%d",i); t.endWrite(); 312 343 return t; 313 344 } 314 const SString&SString::valueOf(long i)315 { 316 staticSString t;345 SString SString::valueOf(long i) 346 { 347 SString t; 317 348 sprintf(t.directWrite(20),"%d",i); t.endWrite(); 318 349 return t; 319 350 } 320 const SString&SString::valueOf(double d)321 { 322 staticSString t;351 SString SString::valueOf(double d) 352 { 353 SString t; 323 354 sprintf(t.directWrite(20),"%g",d); t.endWrite(); 324 355 return t; 325 356 } 326 const SString&SString::valueOf(const SString& s)357 SString SString::valueOf(const SString& s) 327 358 { 328 359 return s;
Note: See TracChangeset
for help on using the changeset viewer.