[Tizen] ResizeUninitialized for some memory copy action 75/277675/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 12 Jul 2022 05:03:21 +0000 (14:03 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 12 Jul 2022 05:03:21 +0000 (14:03 +0900)
Change-Id: I1f9aa60738937a26543a4681f318d9ddca34c1d5
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/adaptor-framework/android/file-loader-impl-android.cpp
dali/internal/adaptor-framework/generic/file-loader-impl-generic.cpp
dali/internal/imaging/common/file-download.cpp
dali/internal/imaging/common/image-operations.cpp
dali/internal/imaging/common/loader-ico.cpp
dali/internal/imaging/common/loader-jpeg-turbo.cpp
dali/internal/imaging/common/loader-png.cpp
dali/internal/imaging/common/loader-wbmp.cpp

index 06abd6a..fba15dc 100644 (file)
@@ -93,7 +93,8 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector
     if( asset )
     {
       length = AAsset_getLength( asset );
-      memblock.Resize( length + 1 ); // 1 for extra zero at the end
+      memblock.ResizeUninitialized( length + 1 );
+      memblock[length] = 0;// 1 for extra zero at the end
 
       char* buffer = reinterpret_cast<char*>(memblock.Begin());
       errorCode = ( AAsset_read( asset, buffer, length ) != length ) ? 0 : 1;
@@ -113,7 +114,6 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector
     {
       fseek( file, 0, SEEK_END );
       length = ftell( file );
-      //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;
index f81d01f..b6d211e 100644 (file)
@@ -69,7 +69,7 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector
   {
     fileSize = file->tellg();
 
-    memblock.Resize( fileSize );
+    memblock.ResizeUninitialized( fileSize );
 
     file->seekg (0, std::ios::beg);
     file->read( reinterpret_cast<char*>(memblock.Begin()), fileSize );
index 534eb75..d9839d2 100755 (executable)
@@ -148,7 +148,7 @@ CURLcode DownloadFileDataByChunk( CURL* curlHandle, Dali::Vector<uint8_t>& dataB
   {
     dataSize += chunks[i].data.capacity();
   }
-  dataBuffer.Resize(dataSize);
+  dataBuffer.ResizeUninitialized(dataSize);
 
   size_t offset = 0;
   for( size_t i=0; i<chunks.size() ; ++i )
index d75e027..e1a1e9c 100755 (executable)
@@ -1974,7 +1974,7 @@ void Resample( const unsigned char * __restrict__ inPixels,
                                  NULL,           // Pclist_y. Optional pointers to contributor lists from another instance of a Resampler.
                                  FILTER_SCALE,   // src_x_ofs,
                                  FILTER_SCALE ); // src_y_ofs. Offset input image by specified amount (fractional values okay).
-  samples[0].Resize( srcWidth );
+  samples[0].ResizeUninitialized( srcWidth );
   for( int i = 1; i < numChannels; ++i )
   {
     resamplers[i] = new Resampler( srcWidth,
@@ -1989,7 +1989,7 @@ void Resample( const unsigned char * __restrict__ inPixels,
                                    resamplers[0]->get_clist_y(),
                                    FILTER_SCALE,
                                    FILTER_SCALE );
-    samples[i].Resize( srcWidth );
+    samples[i].ResizeUninitialized( srcWidth );
   }
 
   const int srcPitch = srcWidth * numChannels;
index 23331c3..92fa820 100755 (executable)
@@ -203,7 +203,7 @@ bool LoadIcoHeaderHelper( FILE* fp,
   {
     return false;
   }
-  map.Resize(fsize);
+  map.ResizeUninitialized(fsize);
 
   if(fread(&map[0], 1, fsize, fp) != fsize)
   {
@@ -591,7 +591,7 @@ bool LoadBitmapFromIco( const Dali::ImageLoader::Input& input, Dali::Devel::Pixe
   Dali::Vector<unsigned int> surface;
   Dali::Vector<unsigned char> maskbuf;
   Dali::Vector<unsigned char> pixbuf;
-  pal.Resize(256 * 4);
+  pal.ResizeUninitialized(256 * 4);
 
   unsigned int dword;
   unsigned short word;
@@ -640,7 +640,7 @@ bool LoadBitmapFromIco( const Dali::ImageLoader::Input& input, Dali::Devel::Pixe
   }
 
   // Set up the surface as soon as we have the width and height, so we have a black image if there are any further errors.
-  surface.Resize( w * h * 4 );
+  surface.ResizeUninitialized( w * h * 4 );
   memset( &surface[0], 0, w * h * 4 );
 
   if (!read_ushort(&map[0], fsize, &position, &word))
@@ -709,8 +709,8 @@ bool LoadBitmapFromIco( const Dali::ImageLoader::Input& input, Dali::Devel::Pixe
   unsigned int bitStride = ( ( w + 31 ) / 32 ) * 4;
 
   // Pixbuf only ever contains one scanline worth of data.
-  pixbuf.Resize( stride );
-  maskbuf.Resize( bitStride * h );
+  pixbuf.ResizeUninitialized( stride );
+  maskbuf.ResizeUninitialized( bitStride * h );
 
   // Handle different bits-per-pixel.
   if(!HandleBitsPerPixel(bitcount, map, pix, surface, w, h, fsize, position, pixbuf, stride, pal))
index f321f03..f448d97 100755 (executable)
@@ -369,7 +369,7 @@ void Transverse(PixelArray buffer, int width, int height)
 {
   using PixelT = PixelType<N>;
   Vector<PixelT> data;
-  data.Resize( width * height );
+  data.ResizeUninitialized( width * height );
   auto dataPtr = data.Begin();
 
   auto original = reinterpret_cast<PixelT*>(buffer);
@@ -392,7 +392,7 @@ void Rotate90(PixelArray buffer, int width, int height)
 {
   using PixelT = PixelType<N>;
   Vector<PixelT> data;
-  data.Resize(width * height);
+  data.ResizeUninitialized(width * height);
   auto dataPtr = data.Begin();
 
   auto original = reinterpret_cast<PixelT*>(buffer);
@@ -421,7 +421,7 @@ void Rotate180(PixelArray buffer, int width, int height)
 {
   using PixelT = PixelType<N>;
   Vector<PixelT> data;
-  data.Resize(width * height);
+  data.ResizeUninitialized(width * height);
   auto dataPtr = data.Begin();
 
   auto original = reinterpret_cast<PixelT*>(buffer);
@@ -445,7 +445,7 @@ void Rotate270(PixelArray buffer, int width, int height)
 {
   using PixelT = PixelType<N>;
   Vector<PixelT> data;
-  data.Resize(width * height);
+  data.ResizeUninitialized(width * height);
   auto dataPtr = data.Begin();
 
   auto original = reinterpret_cast<PixelT*>(buffer);
@@ -560,7 +560,7 @@ bool LoadBitmapFromJpeg( const Dali::ImageLoader::Input& input, Dali::Devel::Pix
   Vector<unsigned char> jpegBuffer;
   try
   {
-    jpegBuffer.Resize( jpegBufferSize );
+    jpegBuffer.ResizeUninitialized( jpegBufferSize );
   }
   catch(...)
   {
@@ -898,7 +898,7 @@ bool EncodeToJpeg( const unsigned char* const pixelBuffer, Vector< unsigned char
       return false;
     }
 
-    encodedPixels.Resize( dstBufferSize );
+    encodedPixels.ResizeUninitialized( dstBufferSize );
     memcpy( encodedPixels.Begin(), dstBuffer.get(), dstBufferSize );
   }
   return true;
index 34050fc..7819783 100644 (file)
@@ -366,7 +366,7 @@ namespace
       if(encoded_img)
       {
         const Vector<unsigned char>::SizeType bufferSize = encoded_img->Count();
-        encoded_img->Resize( bufferSize + length ); //< Can throw OOM.
+        encoded_img->ResizeUninitialized( bufferSize + length ); //< Can throw OOM.
         unsigned char* const bufferBack = encoded_img->Begin() + bufferSize;
         memcpy(bufferBack, data, length);
       }
index 6942442..668698a 100755 (executable)
@@ -142,7 +142,7 @@ bool LoadBitmapFromWbmp( const Dali::ImageLoader::Input& input, Dali::Devel::Pix
     DALI_LOG_ERROR("Error: WBMP size is too large!\n");
     return false;
   }
-  map.Resize(fsize);
+  map.ResizeUninitialized(fsize);
 
   if(fread(&map[0], 1, fsize, fp) != fsize)
   {
@@ -176,7 +176,7 @@ bool LoadBitmapFromWbmp( const Dali::ImageLoader::Input& input, Dali::Devel::Pix
     return false;
   }
 
-  surface.Resize(w* h );//(w * h * 4);
+  surface.ResizeUninitialized(w* h );//(w * h * 4);
   memset(&surface[0], 0, w * h ); // w * h * 4
 
   line_length = (w + 7) >> 3;
@@ -257,7 +257,7 @@ bool LoadWbmpHeader( const Dali::ImageLoader::Input& input, unsigned int& width,
   unsigned int headerSize = 1 + 1 + 4 + 4;// 8 + 8 + 32 + 32;
   headerSize = std::min(headerSize, fsize);
 
-  map.Resize(headerSize);
+  map.ResizeUninitialized(headerSize);
   if(fread(&map[0], 1, headerSize, fp) != headerSize)
   {
     DALI_LOG_WARNING("image file read opeation error!\n");