diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2019-12-20 14:46:36 +0000 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2019-12-20 15:58:13 +0100 |
commit | cc20571fcde14814d6b41582f111042c66435a2d (patch) | |
tree | cbf9d646f015f9dfa64169da787c3a7f6853079b /sal | |
parent | tdf#126966: Tweak to get the "color bar" below text color controls to show up (diff) | |
download | core-cc20571fcde14814d6b41582f111042c66435a2d.tar.gz core-cc20571fcde14814d6b41582f111042c66435a2d.zip |
android: very nasty WIP in-memory cache.
Change-Id: I5ea340c731f76da7e468e1227090d29dbf7fd939
Reviewed-on: https://gerrit.libreoffice.org/85610
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/unx/file.cxx | 69 |
1 files changed, 60 insertions, 9 deletions
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index 9f888579e3a9..576b9bbcf89c 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -815,6 +815,28 @@ static oslFileError openMemoryAsFile(void *address, size_t size, oslFileHandle * #define OPEN_CREATE_FLAGS ( O_CREAT | O_RDWR ) #endif +/* + * Reading files from /assets/ on Android is really slow; we should cache + * small files, particularly sidebar data we need rapidly. + */ +#ifdef ANDROID +struct ACacheEntry { + OString aFilePath; + OString aData; +}; +static size_t nHitCacheEntry = 0; +static ACacheEntry aHitCache[16]; +// static ACacheEntry aMissCache[32]; + +ACacheEntry *aCacheFind(ACacheEntry *pCache, int size, const char *cpFilePath) +{ + for (int i = 0; i < size; ++i) + if (!strcmp(pCache[i].aFilePath.getStr(), cpFilePath)) + return pCache + i; + return nullptr; +} +#endif + oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uInt32 uFlags, mode_t mode) { @@ -828,21 +850,50 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uI { void* address; size_t size; - AAssetManager* mgr = lo_get_native_assetmgr(); - AAsset* asset = AAssetManager_open(mgr, cpFilePath + sizeof("/assets/")-1, AASSET_MODE_BUFFER); - if (!asset) + ACacheEntry *pHit; + + pHit = aCacheFind(aHitCache, SAL_N_ELEMENTS(aHitCache), cpFilePath); + if (pHit) + { + size = pHit->aData.getLength(); + address = malloc(sizeof(char)*size); + memcpy(address, pHit->aData.getStr(), size); + } + // FIXME: make a proper cache class [!] +/* else if (pHit = aCacheFind(aMissCache, SAL_N_ELEMENTS(aMissCache), cpFilePath)) { address = NULL; errno = ENOENT; - __android_log_print(ANDROID_LOG_ERROR,"libo:sal/osl/unx/file", "failed to open %s", cpFilePath); + __android_log_print(ANDROID_LOG_ERROR,"libo:sal/osl/unx/file", "failed to open via miss cache %s", cpFilePath); return osl_File_E_NOENT; - } + } */ else { - size = AAsset_getLength(asset); - address = malloc(sizeof(char)*size); - AAsset_read(asset,address,size); - AAsset_close(asset); + AAssetManager* mgr = lo_get_native_assetmgr(); + AAsset* asset = AAssetManager_open(mgr, cpFilePath + sizeof("/assets/")-1, AASSET_MODE_BUFFER); + if (!asset) + { + address = NULL; + errno = ENOENT; + __android_log_print(ANDROID_LOG_ERROR,"libo:sal/osl/unx/file", "failed to open %s", cpFilePath); + // FIXME: populate aMissCache[ + return osl_File_E_NOENT; + } + else + { + size = AAsset_getLength(asset); + address = malloc(sizeof(char)*size); + AAsset_read(asset,address,size); + AAsset_close(asset); + + if (size < 50 * 1024) + { + size_t nIdx = nHitCacheEntry % SAL_N_ELEMENTS(aHitCache); + aHitCache[nIdx].aFilePath = OString(cpFilePath, strlen(cpFilePath)); + aHitCache[nIdx].aData = OString((char *)address, size); + nHitCacheEntry++; + } + } } if (uFlags & osl_File_OpenFlag_Write) |