MCPcopy Create free account
hub / github.com/beefytech/Beef / GetString

Method GetString

IDEHelper/Compiler/CeMachine.cpp:4145–4183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4143}
4144
4145addr_ce CeContext::GetString(int stringId)
4146{
4147 addr_ce* ceAddrPtr = NULL;
4148 if (!mStringMap.TryAdd(stringId, NULL, &ceAddrPtr))
4149 return *ceAddrPtr;
4150
4151 BfTypeInstance* stringTypeInst = (BfTypeInstance*)mCeMachine->mCeModule->ResolveTypeDef(mCeMachine->mCompiler->mStringTypeDef, BfPopulateType_Data);
4152
4153 String str;
4154 BfStringPoolEntry* entry = NULL;
4155 if (mCeMachine->mCeModule->mContext->mStringObjectIdMap.TryGetValue(stringId, &entry))
4156 {
4157 entry->mLastUsedRevision = mCeMachine->mCompiler->mRevision;
4158 str = entry->mString;
4159 }
4160
4161 int allocSize = stringTypeInst->mInstSize + (int)str.length() + 1;
4162 int charsOffset = stringTypeInst->mInstSize;
4163
4164 uint8* mem = CeMallocZero(allocSize);
4165
4166 auto lenByteCount = stringTypeInst->mFieldInstances[0].mResolvedType->mSize;
4167 auto lenOffset = stringTypeInst->mFieldInstances[0].mDataOffset;
4168 auto allocSizeOffset = stringTypeInst->mFieldInstances[1].mDataOffset;
4169 auto ptrOffset = stringTypeInst->mFieldInstances[2].mDataOffset;
4170
4171 // Write TypeId into there
4172 *(int32*)(mem) = stringTypeInst->mTypeId;
4173 *(int32*)(mem + lenOffset) = (int)str.length();
4174 if (lenByteCount == 4)
4175 *(int32*)(mem + allocSizeOffset) = 0x40000000 + (int)str.length() + 1;
4176 else
4177 *(int64*)(mem + allocSizeOffset) = 0x4000000000000000LL + (int)str.length() + 1;
4178 *(int32*)(mem + ptrOffset) = (mem + charsOffset) - mMemory.mVals;
4179 memcpy(mem + charsOffset, str.c_str(), str.length());
4180
4181 *ceAddrPtr = mem - mMemory.mVals;
4182 return *ceAddrPtr;
4183}
4184
4185addr_ce CeContext::GetString(const StringImpl& str)
4186{

Callers 2

WriteConstantMethod · 0.45
GetAddrMethod · 0.45

Calls 6

TryGetValueMethod · 0.80
GetStringLiteralIdMethod · 0.80
TryAddMethod · 0.45
ResolveTypeDefMethod · 0.45
lengthMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected