From: Cheng-Shiun Tsai Date: Fri, 10 Jul 2020 08:49:19 +0000 (+0100) Subject: Avoid execessive Pushback when Dali::Vector used as file buffer container X-Git-Tag: dali_1.9.31~4 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git;a=commitdiff_plain;h=048aa440fb1979ec2b6d25d4be758428881eed89 Avoid execessive Pushback when Dali::Vector used as file buffer container dali-adator file reader uses Dali::Vector as the container for data buffer. However, Dali::Vector::Resize always initialize the element by doing PushBack(). Considering now you need to read a file of 1MB, Resize() would lead to PushBack() of one byte X one million times, so that it becomes a vector of 1MB, this is unnecessary waste of CPU time. We need another method which simply allocates the buffer without initialize the value. It will help use cases such as MCD Avatar3D / AREmoji where there are a lot of resource files Depends on https://review.tizen.org/gerrit/#/c/platform/core/uifw/dali-core/+/238235/ Change-Id: I560ec768a61e3b41c88775397a87f692f3342d54 --- diff --git a/dali/internal/adaptor-framework/android/file-loader-impl-android.cpp b/dali/internal/adaptor-framework/android/file-loader-impl-android.cpp index c35e70f..f0170e3 100644 --- a/dali/internal/adaptor-framework/android/file-loader-impl-android.cpp +++ b/dali/internal/adaptor-framework/android/file-loader-impl-android.cpp @@ -105,7 +105,10 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector { fseek( file, 0, SEEK_END ); length = ftell( file ); - memblock.Resize( length + 1 ); // 1 for extra zero at the end + //Dali::Vector.Resize would lead to calling PushBack for each byte, waste of CPU resource + memblock.ResizeUninitialized( length + 1 ); + //put last byte as 0, in case this is a text file without null-terminator + memblock[length] = 0; char* buffer = &memblock[0]; fseek( file, 0, SEEK_SET );