nsresult DOMStorageManager::GetStorageInternal(bool aCreate, nsIPrincipal* aPrincipal, const nsAString& aDocumentURI, bool aPrivate, nsIDOMStorage** aRetval) { nsresult rv; nsAutoCString scope; rv = CreateScopeKey(aPrincipal, scope); if (NS_FAILED(rv)) { return NS_ERROR_NOT_AVAILABLE; } nsRefPtr<DOMStorageCache> cache = GetCache(scope); // Get or create a cache for the given scope if (!cache) { if (!aCreate) { *aRetval = nullptr; return NS_OK; } if (!aRetval) { // This is demand to just preload the cache, if the scope has // no data stored, bypass creation and preload of the cache. DOMStorageDBBridge* db = DOMStorageCache::GetDatabase(); if (db) { if (!db->ShouldPreloadScope(scope)) { return NS_OK; } } else { if (scope.Equals(NS_LITERAL_CSTRING("knalb.:about"))) { return NS_OK; } } } // There is always a single instance of a cache per scope // in a single instance of a DOM storage manager. cache = PutCache(scope, aPrincipal); } else if (mType == SessionStorage) { if (!cache->CheckPrincipal(aPrincipal)) { return NS_ERROR_DOM_SECURITY_ERR; } } if (aRetval) { *aRetval = new DOMStorage(this, cache, aDocumentURI, aPrincipal, aPrivate); NS_ADDREF(*aRetval); } return NS_OK; }
//キャッシュにあればコピー //ph:アーカイブ情報を受け取るハンドルへのポインタ //pinfo:アーカイブのファイル情報を受け取るポインタ // あらかじめ pinfo に filename か position をセットしておく。 // キャッシュがあれば filename(position) の一致する情報を返す。 //キャッシュになければ、SPI_NO_FUNCTION が返る。 //キャッシュにあれば SPI_ALL_RIGHT が返る。 //アーカイブ情報はキャッシュにあるが、filename(position) が一致しない場合は //SPI_NOT_SUPPORT が返る。エラーの場合はエラーコードが返る。 int InfoCache::Dupli(char *filepath, HLOCAL *ph, fileInfo *pinfo) { cs.Enter(); HLOCAL hinfo; int ret = GetCache(filepath, &hinfo); if (ret) { ret = SPI_ALL_RIGHT; if (ph != NULL) { UINT size = LocalSize(hinfo); /* 出力用のメモリの割り当て */ *ph = LocalAlloc(LMEM_FIXED, size); if (*ph == NULL) { ret = SPI_NO_MEMORY; } else { memcpy(*ph, (void*)hinfo, size); } } else { fileInfo *ptmp = (fileInfo *)hinfo; if (pinfo->filename[0] != '\0') { for (;;) { if (ptmp->method[0] == '\0') { ret = SPI_NOT_SUPPORT; break; } // complete path relative to archive root char path[sizeof(ptmp->path)+sizeof(ptmp->filename)]; strcpy(path, ptmp->path); size_t len = strlen(path); if(len && path[len-1] != '/' && path[len-1] != '\\') // need delimiter strcat(path, "\\"); strcat(path, ptmp->filename); if (lstrcmpi(path, pinfo->filename) == 0) break; ptmp++; } } else { for (;;) { if (ptmp->method[0] == '\0') { ret = SPI_NOT_SUPPORT; break; } if (ptmp->position == pinfo->position) break; ptmp++; } } if (ret == SPI_ALL_RIGHT) *pinfo = *ptmp; } } else { ret = SPI_NO_FUNCTION; } cs.Leave(); return ret; }
void Moose::Graphics::CVertexDescriptor::UpdateCache( ) { if ( IsCached() ) { glBindBuffer(GL_ARRAY_BUFFER, GetCache()); glBufferData( GL_ARRAY_BUFFER, GetByteSize(), GetPointer<float>(), ( (GetUsage() == Moose::Core::CACHE_DYNAMIC) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW )); glBindBuffer(GL_ARRAY_BUFFER, 0); SetState(Moose::Core::CACHE_UP2DATE); } }
Tcl_Obj * TclThreadAllocObj(void) { register Cache *cachePtr = TclpGetAllocCache(); register Tcl_Obj *objPtr; if (cachePtr == NULL) { cachePtr = GetCache(); } /* * Get this thread's obj list structure and move or allocate new objs if * necessary. */ if (cachePtr->numObjects == 0) { register int numMove; Tcl_MutexLock(objLockPtr); numMove = sharedPtr->numObjects; if (numMove > 0) { if (numMove > NOBJALLOC) { numMove = NOBJALLOC; } MoveObjs(sharedPtr, cachePtr, numMove); } Tcl_MutexUnlock(objLockPtr); if (cachePtr->numObjects == 0) { Tcl_Obj *newObjsPtr; cachePtr->numObjects = numMove = NOBJALLOC; newObjsPtr = malloc(sizeof(Tcl_Obj) * numMove); if (newObjsPtr == NULL) { Tcl_Panic("alloc: could not allocate %d new objects", numMove); } while (--numMove >= 0) { objPtr = &newObjsPtr[numMove]; objPtr->internalRep.otherValuePtr = cachePtr->firstObjPtr; cachePtr->firstObjPtr = objPtr; } } } /* * Pop the first object. */ objPtr = cachePtr->firstObjPtr; cachePtr->firstObjPtr = objPtr->internalRep.otherValuePtr; --cachePtr->numObjects; return objPtr; }
ContentType GetContentType(const ea::string& resourcePath) { auto extension = GetExtension(resourcePath).to_lower(); if (extension == ".xml") { auto systemUI = (SystemUI*)ui::GetIO().UserData; ea::shared_ptr<XMLFile> xml(systemUI->GetCache()->GetResource<XMLFile>(resourcePath)); if (!xml) return CTYPE_UNKNOWN; auto rootElementName = xml->GetRoot().GetName(); if (rootElementName == "scene") return CTYPE_SCENE; if (rootElementName == "node") return CTYPE_SCENEOBJECT; if (rootElementName == "elements") return CTYPE_UISTYLE; if (rootElementName == "element") return CTYPE_UILAYOUT; if (rootElementName == "material") return CTYPE_MATERIAL; if (rootElementName == "particleeffect") return CTYPE_PARTICLE; if (rootElementName == "renderpath") return CTYPE_RENDERPATH; if (rootElementName == "texture") return CTYPE_TEXTUREXML; } if (extension == ".mdl") return CTYPE_MODEL; if (extension == ".ani") return CTYPE_ANIMATION; if (extension == ".scene") return CTYPE_SCENE; if (extension == ".ui") return CTYPE_UILAYOUT; if (extension == ".style") return CTYPE_UISTYLE; if (extension == ".material") return CTYPE_MATERIAL; if (extension == ".particle") return CTYPE_PARTICLE; if (extension == ".node") return CTYPE_SCENEOBJECT; if (audioExtensions_.contains(extension)) return CTYPE_SOUND; if (imagesExtensions_.contains(extension)) return CTYPE_TEXTURE; return CTYPE_UNKNOWN; }
char * TclpAlloc( unsigned int reqSize) { Cache *cachePtr = TclpGetAllocCache(); Block *blockPtr; register int bucket; size_t size; if (cachePtr == NULL) { cachePtr = GetCache(); } /* * Increment the requested size to include room for the Block structure. * Call malloc() directly if the required amount is greater than the * largest block, otherwise pop the smallest block large enough, * allocating more blocks if necessary. */ blockPtr = NULL; size = reqSize + sizeof(Block); #if RCHECK ++size; #endif if (size > MAXALLOC) { bucket = NBUCKETS; blockPtr = malloc(size); if (blockPtr != NULL) { cachePtr->totalAssigned += reqSize; } } else { bucket = 0; while (bucketInfo[bucket].blockSize < size) { ++bucket; } if (cachePtr->buckets[bucket].numFree || GetBlocks(cachePtr, bucket)) { blockPtr = cachePtr->buckets[bucket].firstPtr; cachePtr->buckets[bucket].firstPtr = blockPtr->nextBlock; --cachePtr->buckets[bucket].numFree; ++cachePtr->buckets[bucket].numRemoves; cachePtr->buckets[bucket].totalAssigned += reqSize; } } if (blockPtr == NULL) { return NULL; } return Block2Ptr(blockPtr, bucket, reqSize); }
Moose::Graphics::CVertexDescriptor::~CVertexDescriptor() { switch ( GetType() ) { case ELEMENT_TYPE_VERTEX_3F: case ELEMENT_TYPE_TEX_2F: case ELEMENT_TYPE_UNIFORM_4X4F: case ELEMENT_TYPE_UNIFORM_3X3F: case ELEMENT_TYPE_UNIFORM_2X2F: case ELEMENT_TYPE_UNIFORM_4F: case ELEMENT_TYPE_UNIFORM_3F: case ELEMENT_TYPE_UNIFORM_2F: case ELEMENT_TYPE_UNIFORM_1F: case ELEMENT_TYPE_ATTRIB_1F: case ELEMENT_TYPE_ATTRIB_2F: case ELEMENT_TYPE_ATTRIB_3F: case ELEMENT_TYPE_ATTRIB_4F: case ELEMENT_TYPE_COLOR_3F: case ELEMENT_TYPE_COLOR_4F: case ELEMENT_TYPE_NORMAL_3F: case ELEMENT_TYPE_TEX_3F: case ELEMENT_TYPE_TEX_4F: case ELEMENT_TYPE_V3F_N3F_T2F: delete [] reinterpret_cast<float *>(m_pData); break; case ELEMENT_TYPE_COLOR_4UB: case ELEMENT_TYPE_ATTRIB_1UB: case ELEMENT_TYPE_ATTRIB_2UB: case ELEMENT_TYPE_ATTRIB_3UB: case ELEMENT_TYPE_ATTRIB_4UB: delete [] reinterpret_cast<unsigned char *>(m_pData); break; case ELEMENT_TYPE_UNIFORM_4I: case ELEMENT_TYPE_UNIFORM_3I: case ELEMENT_TYPE_UNIFORM_2I: case ELEMENT_TYPE_UNIFORM_1I: case ELEMENT_TYPE_ATTRIB_1I: case ELEMENT_TYPE_ATTRIB_2I: case ELEMENT_TYPE_ATTRIB_3I: case ELEMENT_TYPE_ATTRIB_4I: delete [] reinterpret_cast<int *>(m_pData); break; case ELEMENT_TYPE_ROCKET_DATA: delete [] reinterpret_cast<Rocket::Core::Vertex *>(m_pData); break; } m_pData = NULL; if ( IsCached() ) glDeleteBuffers( 1, &GetCache()); }
BakedResourceRouter::BakedResourceRouter(Context* context) : ResourceRouter(context) { ea::shared_ptr<JSONFile> file(GetCache()->GetResource<JSONFile>("CacheInfo.json")); if (file) { const auto& info = file->GetRoot().GetObject(); for (auto it = info.begin(); it != info.end(); it++) { const JSONArray& files = it->second["files"].GetArray(); if (files.size() == 1) routes_[it->first] = files[0].GetString(); } } }
static apr_status_t AddCache( const char *key, void *data, size_t size, time_t mtime ) { apr_status_t rc = APR_SUCCESS; kIOCache_t *c = GetCache(); if( c && c->store ) { apr_pool_t *p = NULL; kIOCacheFile_t *cfile = (kIOCacheFile_t*)apr_hash_get( c->hash, key, APR_HASH_KEY_STRING ); char *epoch = NULL; size_t elen = 0; // free if cache exist if( cfile ){ c->size -= cfile->size; apr_hash_set( c->hash, cfile->key, APR_HASH_KEY_STRING, NULL ); apr_pool_destroy( cfile->p ); cfile = NULL; } // create cache packet if( ( rc = kahanaMalloc( c->p, sizeof( kIOCacheFile_t ), (void**)&cfile, &p ) ) ){ kahanaLogPut( NULL, NULL, "failed to kahanaMalloc(): %s", STRERROR_APR( rc ) ); } else if( ( elen = asprintf( &epoch, "|%lld", (long long)mtime ) ) == -1 ){ rc = errno; apr_pool_destroy( p ); kahanaLogPut( NULL, NULL, "failed to asprintf(): %s", strerror( rc ) ); } else { cfile->p = p; cfile->key = (const char*)apr_pstrdup( p, key ); cfile->size = size; cfile->data = (void*)apr_pcalloc( p, size + elen ); memcpy( cfile->data, data, size ); memcpy( cfile->data + size, epoch, elen ); ((unsigned char*)cfile->data)[size + elen] = '\0'; c->size += size + elen; apr_hash_set( c->hash, cfile->key, APR_HASH_KEY_STRING, (void*)cfile ); free( epoch ); } } return rc; }
bool BacteroidsState::Initialize() { GetWindow().GrabMouse(); Renderer &renderer = GetRenderer(); m_playerShader = renderer.CompileShaderProgram(g_playerShader.m_vertexShader, g_playerShader.m_fragmentShader); m_bacterShader = renderer.CompileShaderProgram(g_bacterShader.m_vertexShader, g_bacterShader.m_fragmentShader); m_projectileShader = renderer.CompileShaderProgram(g_projectileShader.m_vertexShader, g_projectileShader.m_fragmentShader); m_fontShader = renderer.CompileShaderProgram(g_fontShader.m_vertexShader, g_fontShader.m_fragmentShader); m_uniforms.m_velocity = renderer.GetGraphics()->CreateUniform("u_velocity", UniformType::Vec4); m_uniforms.m_anim = renderer.GetGraphics()->CreateUniform("u_anim", UniformType::Float); renderer.GetGraphics()->AddProgramUniform(m_playerShader, m_uniforms.m_velocity); renderer.GetGraphics()->AddProgramUniform(m_projectileShader, m_uniforms.m_velocity); renderer.GetGraphics()->AddProgramUniform(m_bacterShader, m_uniforms.m_anim); renderer.GetGraphics()->AddProgramUniform(m_bacterShader, m_uniforms.m_velocity); Player::shader = m_playerShader; Bacter::shader = m_bacterShader; Projectile::shader = m_projectileShader; m_soundPlayer.Init(GetAudio(), GetCache()); m_player.SetPosition(0.0f, 0.0f); m_objects.Init(GetAllocator()); m_objects.AddObject(&m_player); m_quadTree = GetAllocator().AllocateArray<GameObject*>(MAX_OBJECTS); m_score = 0; m_kills = 0; m_damageFade.SetFadeAcceleration(-10.0f); for (size_t_32 i = 0; i < 6; i++) SpawnBacter(0.5f); return true; }
void TclpFree( char *ptr) { Cache *cachePtr; Block *blockPtr; int bucket; if (ptr == NULL) { return; } cachePtr = TclpGetAllocCache(); if (cachePtr == NULL) { cachePtr = GetCache(); } /* * Get the block back from the user pointer and call system free directly * for large blocks. Otherwise, push the block back on the bucket and move * blocks to the shared cache if there are now too many free. */ blockPtr = Ptr2Block(ptr); bucket = blockPtr->sourceBucket; if (bucket == NBUCKETS) { cachePtr->totalAssigned -= blockPtr->blockReqSize; free(blockPtr); return; } cachePtr->buckets[bucket].totalAssigned -= blockPtr->blockReqSize; blockPtr->nextBlock = cachePtr->buckets[bucket].firstPtr; cachePtr->buckets[bucket].firstPtr = blockPtr; ++cachePtr->buckets[bucket].numFree; ++cachePtr->buckets[bucket].numInserts; if (cachePtr != sharedPtr && cachePtr->buckets[bucket].numFree > bucketInfo[bucket].maxBlocks) { PutBlocks(cachePtr, bucket, bucketInfo[bucket].numMove); } }
static PyObject* WrapCore(PyObject *oldCap, bool owned) { auto_pyobject cap = PyObject_CallFunctionObjArgs(GetCapsuleClass(), oldCap, NULL); auto_pyobject cls = PyObject_CallMethod(*cap, "get_class", ""); auto_pyobject addr = GetPointer(oldCap); // look up cached object auto_pyobject cache_cls = PyObject_GetItem(GetCache(), *cls); Assert(*cache_cls); PyObject* obj = NULL; obj = PyObject_GetItem(*cache_cls, *addr); if (obj) { /* cache hit */ } else { if (!PyErr_ExceptionMatches(PyExc_KeyError)) return NULL; /* cache miss */ PyErr_Clear(); if (!owned) { auto_pyobject hasDtor = PyObject_CallMethod(*cls, "_has_dtor", ""); if (PyObject_IsTrue(*hasDtor)) { auto_pyobject name = GetName(oldCap); auto_pyobject key = PyTuple_Pack(2, *name, *addr); auto_pyobject val = PyObject_GetAttrString(*cls, "_delete_"); int ok = PyDict_SetItem(GetAddrDtorDict(), *key, *val); Assert(ok != -1); } } obj = PyObject_CallMethod(*cap, "instantiate", ""); int ok = PyObject_SetItem(*cache_cls, *addr, obj); Assert(ok != -1); } Assert(obj); return obj; }
void CSpyUserPanel::GetFileInfo(const TCHAR* pszFilePath, bool bRefresh) { BEATS_ASSERT(pszFilePath != NULL, _T("File path is NULL!")); bool bUseCache = false; if (!bRefresh) { if (pszFilePath[0] == 0) { if (m_pDiskInfoCache != NULL) { UpdateFileUI(2, m_pDiskInfoCache); bUseCache = true; } } else { if (m_pRootDirectoryCache != NULL) { SDirectory* pDirectory = GetCache(pszFilePath); if (pDirectory != NULL) { UpdateFileUI(1, pDirectory); bUseCache = true; } } } } if (!bUseCache) { typedef void(*TFileInfoFeedbackFunc)(char m_type, void* pFileInfo, void* pUserDataPtr); typedef bool (*TGetFileInfoFunc)(SOCKET sock, const TCHAR* pszCmd, TFileInfoFeedbackFunc pFeedbackFunc, void* pUserDataPtr); static TGetFileInfoFunc pGetFileInfoFunc = TGetFileInfoFunc(GetProcAddress(m_hSpyDllHandle, "Spy_SendFileInfoCommand")); BEATS_ASSERT(pGetFileInfoFunc != NULL, _T("Get function address %s failed!"), _T("Spy_SendFileInfoCommand")); if (pGetFileInfoFunc != NULL) { pGetFileInfoFunc(m_pSocketInfo->m_socket, pszFilePath, OnGetFileInfo, this); } } }
/// Constructs a SimpleBlockFile based on sample data and writes /// it to disk. /// /// @param baseFileName The filename to use, but without an extension. /// This constructor will add the appropriate /// extension (.au in this case). /// @param sampleData The sample data to be written to this block. /// @param sampleLen The number of samples to be written to this block. /// @param format The format of the given samples. /// @param allowDeferredWrite Allow deferred write-caching SimpleBlockFile::SimpleBlockFile(wxFileNameWrapper &&baseFileName, samplePtr sampleData, sampleCount sampleLen, sampleFormat format, bool allowDeferredWrite /* = false */, bool bypassCache /* = false */): BlockFile { (baseFileName.SetExt(wxT("au")), std::move(baseFileName)), sampleLen } { mFormat = format; mCache.active = false; bool useCache = GetCache() && (!bypassCache); if (!(allowDeferredWrite && useCache) && !bypassCache) { bool bSuccess = WriteSimpleBlockFile(sampleData, sampleLen, format, NULL); wxASSERT(bSuccess); // TODO: Handle failure here by alert to user and undo partial op. wxUnusedVar(bSuccess); } if (useCache) { //wxLogDebug("SimpleBlockFile::SimpleBlockFile(): Caching block file data."); mCache.active = true; mCache.needWrite = true; mCache.format = format; mCache.sampleData = new char[sampleLen * SAMPLE_SIZE(format)]; memcpy(mCache.sampleData, sampleData, sampleLen * SAMPLE_SIZE(format)); ArrayOf<char> cleanup; void* summaryData = BlockFile::CalcSummary(sampleData, sampleLen, format, cleanup); mCache.summaryData = new char[mSummaryInfo.totalSummaryBytes]; memcpy(mCache.summaryData, summaryData, (size_t)mSummaryInfo.totalSummaryBytes); } }
NS_IMETHODIMP DOMStorageManager::CheckStorage(nsIPrincipal* aPrincipal, nsIDOMStorage* aStorage, bool* aRetval) { nsresult rv; RefPtr<DOMStorage> storage = static_cast<DOMStorage*>(aStorage); if (!storage) { return NS_ERROR_UNEXPECTED; } *aRetval = false; if (!aPrincipal) { return NS_ERROR_NOT_AVAILABLE; } nsAutoCString suffix; BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(suffix); nsAutoCString origin; rv = AppendOriginNoSuffix(aPrincipal, origin); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } DOMStorageCache* cache = GetCache(suffix, origin); if (cache != storage->GetCache()) { return NS_OK; } if (!storage->PrincipalEquals(aPrincipal)) { return NS_OK; } *aRetval = true; return NS_OK; }
static uint8 SweepStack(RobboTotalBase *tb, uint64 PositionCount) { uint64 n = tb->num; uint64 zo = PositionCount / TotalCachePer, ci = (n << 32) | zo, ZO; int h[4], e, i; uint8 *BPTR; uint8 u; uint64 SaveXOR; Prim: SaveXOR = CurrentXOR; for (i = 0; i < 4; i++) { h[i] = GetCache(i, n, zo); if (CacheInfo[i][h[i]] == ci) { u = TotalBase_Cache[i][h[i]][PositionCount % TotalCachePer]; if (CacheInfo[i][h[i]] == ci) return u; } } Lock(SweepStackLock); if (SaveXOR != CurrentXOR) { UnLock(SweepStackLock); goto Prim; } ExcludeCount++; e = -1; for (i = 0; i < 4; i++) if (CacheInfo[i][h[i]] == 0xffffffff) e = i; if (e == -1) { e = 0; for (i = 0; i < 16; i++) e += (ExcludeCount >> i); e &= 3; }
char * TclpRealloc( char *ptr, unsigned int reqSize) { Cache *cachePtr; Block *blockPtr; void *newPtr; size_t size, min; int bucket; if (ptr == NULL) { return TclpAlloc(reqSize); } if (sizeof(int) >= sizeof(size_t)) { /* An unsigned int overflow can also be a size_t overflow */ const size_t zero = 0; const size_t max = ~zero; if (((size_t) reqSize) > max - sizeof(Block) - RCHECK) { /* Requested allocation exceeds memory */ return NULL; } } cachePtr = TclpGetAllocCache(); if (cachePtr == NULL) { cachePtr = GetCache(); } /* * If the block is not a system block and fits in place, simply return the * existing pointer. Otherwise, if the block is a system block and the new * size would also require a system block, call realloc() directly. */ blockPtr = Ptr2Block(ptr); size = reqSize + sizeof(Block); #if RCHECK ++size; #endif bucket = blockPtr->sourceBucket; if (bucket != NBUCKETS) { if (bucket > 0) { min = bucketInfo[bucket-1].blockSize; } else { min = 0; } if (size > min && size <= bucketInfo[bucket].blockSize) { cachePtr->buckets[bucket].totalAssigned -= blockPtr->blockReqSize; cachePtr->buckets[bucket].totalAssigned += reqSize; return Block2Ptr(blockPtr, bucket, reqSize); } } else if (size > MAXALLOC) { cachePtr->totalAssigned -= blockPtr->blockReqSize; cachePtr->totalAssigned += reqSize; blockPtr = realloc(blockPtr, size); if (blockPtr == NULL) { return NULL; } return Block2Ptr(blockPtr, NBUCKETS, reqSize); } /* * Finally, perform an expensive malloc/copy/free. */ newPtr = TclpAlloc(reqSize); if (newPtr != NULL) { if (reqSize > blockPtr->blockReqSize) { reqSize = blockPtr->blockReqSize; } memcpy(newPtr, ptr, reqSize); TclpFree(ptr); } return newPtr; }
static char * variant_out_int(FunctionCallInfo fcinfo, Variant input) { VariantCache *cache; bool need_quote; char *tmp; char *org_cstring; StringInfoData outd; StringInfo out = &outd; VariantInt vi; Assert(fcinfo->flinfo->fn_strict); /* Must be strict */ vi = make_variant_int(input, fcinfo, IOFunc_output); cache = GetCache(fcinfo); Assert(cache->formatted_name); /* Start building string */ initStringInfo(out); appendStringInfoChar(out, '('); need_quote = false; for (tmp = cache->formatted_name; *tmp; tmp++) { char ch = *tmp; if (ch == '"' || ch == '\\' || ch == '(' || ch == ')' || ch == ',' || isspace((unsigned char) ch)) { need_quote = true; break; } } if(!need_quote) appendStringInfoString(out, cache->formatted_name); else { appendStringInfoChar(out, '"'); for (tmp = cache->formatted_name; *tmp; tmp++) { char ch = *tmp; if (ch == '"' || ch == '\\') appendStringInfoCharMacro(out, ch); appendStringInfoCharMacro(out, ch); } appendStringInfoChar(out, '"'); } appendStringInfoChar(out, ','); if(!vi->isnull) { org_cstring = OutputFunctionCall(&cache->proc, vi->data); /* * Detect whether we need double quotes for this value * * Stolen then modified from record_out. */ need_quote = (org_cstring[0] == '\0' ); /* force quotes for empty string */ if( !need_quote ) { for (tmp = org_cstring; *tmp; tmp++) { char ch = *tmp; if (ch == '"' || ch == '\\' || ch == '(' || ch == ')' || ch == ',' || isspace((unsigned char) ch)) { need_quote = true; break; } } } if (!need_quote) appendStringInfoString(out, org_cstring); else { appendStringInfoChar(out, '"'); for (tmp = org_cstring; *tmp; tmp++) { char ch = *tmp; if (ch == '"' || ch == '\\') appendStringInfoCharMacro(out, ch); appendStringInfoCharMacro(out, ch); } appendStringInfoChar(out, '"'); } } appendStringInfoChar(out, ')'); return out->data; }
IPath::SearchResult IPathFinder::GetPath( const MoveDef& moveDef, const CPathFinderDef& pfDef, const CSolidObject* owner, float3 startPos, IPath::Path& path, const unsigned int maxNodes ) { startPos.ClampInBounds(); // Clear the path path.path.clear(); path.squares.clear(); path.pathCost = PATHCOST_INFINITY; // initial calculations if (isEstimator) { maxBlocksToBeSearched = std::min(MAX_SEARCHED_NODES_PE - 8U, maxNodes); } else { maxBlocksToBeSearched = std::min(MAX_SEARCHED_NODES_PF - 8U, maxNodes); } mStartBlock.x = startPos.x / BLOCK_PIXEL_SIZE; mStartBlock.y = startPos.z / BLOCK_PIXEL_SIZE; mStartBlockIdx = BlockPosToIdx(mStartBlock); assert((unsigned)mStartBlock.x < nbrOfBlocks.x && (unsigned)mStartBlock.y < nbrOfBlocks.y); // Check cache (when there is one) int2 goalBlock; goalBlock.x = pfDef.goalSquareX / BLOCK_SIZE; goalBlock.y = pfDef.goalSquareZ / BLOCK_SIZE; const CPathCache::CacheItem* ci = GetCache(mStartBlock, goalBlock, pfDef.sqGoalRadius, moveDef.pathType, pfDef.synced); if (ci != nullptr) { path = ci->path; return ci->result; } // Start up a new search IPath::SearchResult result = InitSearch(moveDef, pfDef, owner); // If search was successful, generate new path if (result == IPath::Ok || result == IPath::GoalOutOfRange) { FinishSearch(moveDef, pfDef, path); // Save to cache AddCache(&path, result, mStartBlock, goalBlock, pfDef.sqGoalRadius, moveDef.pathType, pfDef.synced); if (LOG_IS_ENABLED(L_DEBUG)) { LOG_L(L_DEBUG, "==== %s: Search completed ====", (isEstimator) ? "PE" : "PF"); LOG_L(L_DEBUG, "Tested blocks: %u", testedBlocks); LOG_L(L_DEBUG, "Open blocks: %u", openBlockBuffer.GetSize()); LOG_L(L_DEBUG, "Path length: " _STPF_, path.path.size()); LOG_L(L_DEBUG, "Path cost: %f", path.pathCost); LOG_L(L_DEBUG, "=============================="); } } else { if (LOG_IS_ENABLED(L_DEBUG)) { LOG_L(L_DEBUG, "==== %s: Search failed! ====", (isEstimator) ? "PE" : "PF"); LOG_L(L_DEBUG, "Tested blocks: %u", testedBlocks); LOG_L(L_DEBUG, "Open blocks: %u", openBlockBuffer.GetSize()); LOG_L(L_DEBUG, "============================"); } } return result; }
as_value Property::getCache() const { return boost::apply_visitor(GetCache(), _bound); }
nsresult DOMStorageManager::GetStorageInternal(bool aCreate, mozIDOMWindow* aWindow, nsIPrincipal* aPrincipal, const nsAString& aDocumentURI, bool aPrivate, nsIDOMStorage** aRetval) { nsresult rv; nsAutoCString originAttrSuffix; BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(originAttrSuffix); nsAutoCString originKey; rv = AppendOriginNoSuffix(aPrincipal, originKey); if (NS_FAILED(rv)) { return NS_ERROR_NOT_AVAILABLE; } RefPtr<DOMStorageCache> cache = GetCache(originAttrSuffix, originKey); // Get or create a cache for the given scope if (!cache) { if (!aCreate) { *aRetval = nullptr; return NS_OK; } if (!aRetval) { // This is a demand to just preload the cache, if the scope has // no data stored, bypass creation and preload of the cache. DOMStorageDBBridge* db = DOMStorageCache::GetDatabase(); if (db) { if (!db->ShouldPreloadOrigin(DOMStorageManager::CreateOrigin(originAttrSuffix, originKey))) { return NS_OK; } } else { if (originKey.EqualsLiteral("knalb.:about")) { return NS_OK; } } } // There is always a single instance of a cache per scope // in a single instance of a DOM storage manager. cache = PutCache(originAttrSuffix, originKey, aPrincipal); } else if (mType == SessionStorage) { if (!cache->CheckPrincipal(aPrincipal)) { return NS_ERROR_DOM_SECURITY_ERR; } } if (aRetval) { nsCOMPtr<nsPIDOMWindowInner> inner = nsPIDOMWindowInner::From(aWindow); nsCOMPtr<nsIDOMStorage> storage = new DOMStorage( inner, this, cache, aDocumentURI, aPrincipal, aPrivate); storage.forget(aRetval); } return NS_OK; }
CNwnMdlModel *CNmcContext::LoadModel (const char *pszName) { // // Search the cache // if (m_pCache) { CNwnMdlModel *pModel = m_pCache ->FindModel (pszName); if (pModel) return pModel; } // // Load the file // bool fAllocated; UINT32 ulSize; unsigned char *pauchData = LoadResource (pszName, NwnResType_MDL, &ulSize, &fAllocated); if (pauchData == NULL) return NULL; // // If the model is binary // if (ulSize > 12 && pauchData [0] == 0 && pauchData [1] == 0 && pauchData [2] == 0 && pauchData [3] == 0) { // // If the buffer isn't allocated, then copy // if (!fAllocated) { unsigned char *p = (unsigned char *) malloc (ulSize); if (p == NULL) return NULL; memcpy (p, pauchData, ulSize); pauchData = p; fAllocated = true; } // // Get pointer to all the information we are interested in // CNwnModel::Header *pHeader = (CNwnModel::Header *) pauchData; unsigned char *pauchModelData = & pauchData [sizeof (CNwnModel::Header)]; unsigned char *pauchRawData = & pauchData [sizeof (CNwnModel::Header) + pHeader ->ulRawDataOffset]; CNwnMdlModel *pModel = (CNwnMdlModel *) pauchModelData; // // Convert the absolute // pModel ->RelativeToAbsolute (pauchModelData, pauchRawData); // // If we have a cache, add the model // if (m_pCache) m_pCache ->AddModel (pModel, pszName); // // Return the model // return pModel; } // // Otherwise, this is ASCII // else { // // Create the stream // CNwnMemoryStream *pStream = new CNwnMemoryStream ( pszName, pauchData, ulSize, fAllocated); // // Start a new compiler // CNmcContext sCtx; sCtx .AddStream (pStream); sCtx .SetCache (GetCache ()); for (int i = 0; i < (int) m_vpKeyFiles .GetCount (); i++) sCtx .AddKeyFile (m_vpKeyFiles [i]); sCtx .SetPurgeNullFaces (GetPurgeNullFaces ()); // // Compile // NmcParseModelFile (&sCtx); if (sCtx .GetErrors ()) { GenerateError ("Supermodel failed to compile."); if (sCtx .GetCurrentModel ()) delete sCtx .GetCurrentModel (); return NULL; } else { if (m_pCache) m_pCache ->AddModel (sCtx .GetCurrentModel (), pszName); return sCtx .GetCurrentModel (); } } }