Avoid execessive Pushback when Dali::Vector<char> used as file buffer container 94/238294/3
authorCheng-Shiun Tsai <cheng.tsai@samsung.com>
Fri, 10 Jul 2020 08:49:19 +0000 (09:49 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Wed, 23 Sep 2020 08:30:12 +0000 (08:30 +0000)
dali-adator file reader uses Dali::Vector<char,true> 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

dali/internal/adaptor-framework/android/file-loader-impl-android.cpp

index c35e70f..f0170e3 100644 (file)
@@ -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 );