| 493 | } |
| 494 | |
| 495 | void ConsoleValue::setStringValue(const char * value) |
| 496 | { |
| 497 | if (value == NULL) value = typeValueEmpty; |
| 498 | |
| 499 | if(type <= ConsoleValue::TypeInternalString) |
| 500 | { |
| 501 | // Let's not remove empty-string-valued global vars from the dict. |
| 502 | // If we remove them, then they won't be exported, and sometimes |
| 503 | // it could be necessary to export such a global. There are very |
| 504 | // few empty-string global vars so there's no performance-related |
| 505 | // need to remove them from the dict. |
| 506 | /* |
| 507 | if(!value[0] && name[0] == '$') |
| 508 | { |
| 509 | gEvalState.globalVars.remove(this); |
| 510 | return; |
| 511 | } |
| 512 | */ |
| 513 | if (value == typeValueEmpty) |
| 514 | { |
| 515 | if (bufferLen > 0) |
| 516 | { |
| 517 | dFree(sval); |
| 518 | bufferLen = 0; |
| 519 | } |
| 520 | |
| 521 | sval = typeValueEmpty; |
| 522 | fval = 0.f; |
| 523 | ival = 0; |
| 524 | type = TypeInternalString; |
| 525 | return; |
| 526 | } |
| 527 | |
| 528 | U32 stringLen = dStrlen(value); |
| 529 | |
| 530 | // If it's longer than 256 bytes, it's certainly not a number. |
| 531 | // |
| 532 | // (This decision may come back to haunt you. Shame on you if it |
| 533 | // does.) |
| 534 | if(stringLen < 256) |
| 535 | { |
| 536 | fval = dAtof(value); |
| 537 | ival = dAtoi(value); |
| 538 | } |
| 539 | else |
| 540 | { |
| 541 | fval = 0.f; |
| 542 | ival = 0; |
| 543 | } |
| 544 | |
| 545 | // may as well pad to the next cache line |
| 546 | U32 newLen = ((stringLen + 1) + 15) & ~15; |
| 547 | |
| 548 | if(bufferLen == 0) |
| 549 | sval = (char *) dMalloc(newLen); |
| 550 | else if(newLen > bufferLen) |
| 551 | sval = (char *) dRealloc(sval, newLen); |
| 552 |
no test coverage detected