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