| 621 | } |
| 622 | |
| 623 | void BfParser::SetSource(const char* data, int length) |
| 624 | { |
| 625 | const int EXTRA_BUFFER_SIZE = 80; // Extra chars for a bit of AllocChars room |
| 626 | |
| 627 | //TODO: Check cache |
| 628 | // Don't cache if we have a Cursorid set, |
| 629 | // if mDataId != -1 |
| 630 | // if BfParerFlag != 0 |
| 631 | |
| 632 | bool canCache = true; |
| 633 | if (mDataId != -1) |
| 634 | canCache = false; |
| 635 | if (mParserFlags != 0) |
| 636 | canCache = false; |
| 637 | if (mCursorIdx != -1) |
| 638 | canCache = false; |
| 639 | if (mCompatMode) |
| 640 | canCache = false; |
| 641 | if (mQuickCompatMode) |
| 642 | canCache = false; |
| 643 | if (mFileName.IsEmpty()) |
| 644 | canCache = false; |
| 645 | if (mProject == NULL) |
| 646 | canCache = false; |
| 647 | if (mIsEmitted) |
| 648 | canCache = false; |
| 649 | |
| 650 | uint64 cacheHash = 0; |
| 651 | if (canCache) |
| 652 | { |
| 653 | AutoCrit autoCrit(gBfParserCache->mCritSect); |
| 654 | |
| 655 | HashContext hashCtx; |
| 656 | hashCtx.MixinStr(mFileName); |
| 657 | hashCtx.Mixin(data, length); |
| 658 | cacheHash = hashCtx.Finish64(); |
| 659 | |
| 660 | BfParserCache::LookupEntry lookupEntry; |
| 661 | lookupEntry.mFileName = mFileName; |
| 662 | lookupEntry.mSrc = data; |
| 663 | lookupEntry.mSrcLength = length; |
| 664 | lookupEntry.mHash = cacheHash; |
| 665 | lookupEntry.mProject = mProject; |
| 666 | |
| 667 | BfParserCache::DataEntry* dataEntryP; |
| 668 | if (gBfParserCache->mEntries.TryGetWith(lookupEntry, &dataEntryP)) |
| 669 | { |
| 670 | mUsingCache = true; |
| 671 | |
| 672 | mParserData = dataEntryP->mParserData; |
| 673 | BF_ASSERT(mParserData->mDidReduce); |
| 674 | |
| 675 | BfLogSysM("Using cached parserData %p for %p %s\n", mParserData, this, mFileName.c_str()); |
| 676 | |
| 677 | mParserData->mRefCount++; |
| 678 | mSourceData = mParserData; |
| 679 | |
| 680 | mSrc = mParserData->mSrc; |
no test coverage detected