From ec7280a42dd8ad1ca2a4ea1e8a942c6d66d45491 Mon Sep 17 00:00:00 2001 From: "huayong.xu" Date: Wed, 15 Feb 2023 16:48:39 +0800 Subject: [PATCH] Replace std::string global variables with C-style string. A std::string global variable would allocate a memory in heap, then copy the string from .text section to the heap. This patch may reduce loading time & memory a little. Change-Id: I124fc778ab00754bc61d1517a18afcb728904483 --- dali/internal/graphics/gles-impl/gles-graphics-texture.cpp | 14 +++++++++----- dali/internal/graphics/gles/egl-implementation.cpp | 14 +++++++------- .../internal/graphics/tizen/egl-image-extensions-tizen.cpp | 6 +++--- dali/internal/system/common/configuration-manager.cpp | 12 ++++++------ .../text/text-abstraction/plugin/font-client-utils.cpp | 10 +++++----- .../window-system/ubuntu-x11/window-base-ecore-x.cpp | 2 +- .../window-system/windows/platform-implement-win.cpp | 4 ++-- dali/internal/window-system/x11/window-base-x.cpp | 2 +- 8 files changed, 34 insertions(+), 30 deletions(-) diff --git a/dali/internal/graphics/gles-impl/gles-graphics-texture.cpp b/dali/internal/graphics/gles-impl/gles-graphics-texture.cpp index f7a2aef..9b997c6 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-texture.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-texture.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,8 +91,12 @@ inline std::vector ConvertRGB32ToRGBA32(const void* pData, uint32_t siz /** * Format conversion table */ -static const std::vector COLOR_CONVERSION_TABLE = { - {Format::R8G8B8_UNORM, Format::R8G8B8A8_UNORM, ConvertRGB32ToRGBA32, WriteRGB32ToRGBA32}}; +const std::vector& GetColorConversionTable() +{ + static const std::vector COLOR_CONVERSION_TABLE = { + {Format::R8G8B8_UNORM, Format::R8G8B8A8_UNORM, ConvertRGB32ToRGBA32, WriteRGB32ToRGBA32}}; + return COLOR_CONVERSION_TABLE; +} /** * Constructor @@ -399,12 +403,12 @@ bool Texture::TryConvertPixelData(const void* pData, Graphics::Format srcFormat, return false; } - auto it = std::find_if(COLOR_CONVERSION_TABLE.begin(), COLOR_CONVERSION_TABLE.end(), [&](auto& item) { + auto it = std::find_if(GetColorConversionTable().begin(), GetColorConversionTable().end(), [&](auto& item) { return item.srcFormat == srcFormat && item.destFormat == destFormat; }); // No suitable format, return empty array - if(it == COLOR_CONVERSION_TABLE.end()) + if(it == GetColorConversionTable().end()) { return false; } diff --git a/dali/internal/graphics/gles/egl-implementation.cpp b/dali/internal/graphics/gles/egl-implementation.cpp index 09d8867..e389671 100644 --- a/dali/internal/graphics/gles/egl-implementation.cpp +++ b/dali/internal/graphics/gles/egl-implementation.cpp @@ -37,13 +37,13 @@ namespace { -const uint32_t THRESHOLD_SWAPBUFFER_COUNT = 5; -const uint32_t CHECK_EXTENSION_NUMBER = 4; -const uint32_t EGL_VERSION_SUPPORT_SURFACELESS_CONTEXT = 15; -const std::string EGL_KHR_SURFACELESS_CONTEXT = "EGL_KHR_surfaceless_context"; -const std::string EGL_KHR_CREATE_CONTEXT = "EGL_KHR_create_context"; -const std::string EGL_KHR_PARTIAL_UPDATE = "EGL_KHR_partial_update"; -const std::string EGL_KHR_SWAP_BUFFERS_WITH_DAMAGE = "EGL_KHR_swap_buffers_with_damage"; +const uint32_t THRESHOLD_SWAPBUFFER_COUNT = 5; +const uint32_t CHECK_EXTENSION_NUMBER = 4; +const uint32_t EGL_VERSION_SUPPORT_SURFACELESS_CONTEXT = 15; +const char* EGL_KHR_SURFACELESS_CONTEXT = "EGL_KHR_surfaceless_context"; +const char* EGL_KHR_CREATE_CONTEXT = "EGL_KHR_create_context"; +const char* EGL_KHR_PARTIAL_UPDATE = "EGL_KHR_partial_update"; +const char* EGL_KHR_SWAP_BUFFERS_WITH_DAMAGE = "EGL_KHR_swap_buffers_with_damage"; // Threshold time in miliseconds constexpr auto PERFORMANCE_LOG_THRESHOLD_TIME_ENV = "DALI_EGL_PERFORMANCE_LOG_THRESHOLD_TIME"; diff --git a/dali/internal/graphics/tizen/egl-image-extensions-tizen.cpp b/dali/internal/graphics/tizen/egl-image-extensions-tizen.cpp index cf79bdb..785f933 100644 --- a/dali/internal/graphics/tizen/egl-image-extensions-tizen.cpp +++ b/dali/internal/graphics/tizen/egl-image-extensions-tizen.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,8 +46,8 @@ PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHRProc = 0; PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHRProc = 0; PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOESProc = 0; -const std::string EGL_TIZEN_IMAGE_NATIVE_SURFACE = "EGL_TIZEN_image_native_surface"; -const std::string EGL_EXT_IMAGE_DMA_BUF_IMPORT = "EGL_EXT_image_dma_buf_import"; +const char* EGL_TIZEN_IMAGE_NATIVE_SURFACE = "EGL_TIZEN_image_native_surface"; +const char* EGL_EXT_IMAGE_DMA_BUF_IMPORT = "EGL_EXT_image_dma_buf_import"; } // unnamed namespace diff --git a/dali/internal/system/common/configuration-manager.cpp b/dali/internal/system/common/configuration-manager.cpp index 0515b46..ff77416 100644 --- a/dali/internal/system/common/configuration-manager.cpp +++ b/dali/internal/system/common/configuration-manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,11 +37,11 @@ namespace Adaptor { namespace { -const std::string SYSTEM_CACHE_FILE = "gpu-environment.conf"; -const std::string DALI_ENV_MULTIPLE_WINDOW_SUPPORT = "DALI_ENV_MULTIPLE_WINDOW_SUPPORT"; -const std::string DALI_BLEND_EQUATION_ADVANCED_SUPPORT = "DALI_BLEND_EQUATION_ADVANCED_SUPPORT"; -const std::string DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT = "DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT"; -const std::string DALI_GLSL_VERSION = "DALI_GLSL_VERSION"; +const char* SYSTEM_CACHE_FILE = "gpu-environment.conf"; +const char* DALI_ENV_MULTIPLE_WINDOW_SUPPORT = "DALI_ENV_MULTIPLE_WINDOW_SUPPORT"; +const char* DALI_BLEND_EQUATION_ADVANCED_SUPPORT = "DALI_BLEND_EQUATION_ADVANCED_SUPPORT"; +const char* DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT = "DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT"; +const char* DALI_GLSL_VERSION = "DALI_GLSL_VERSION"; } // unnamed namespace diff --git a/dali/internal/text/text-abstraction/plugin/font-client-utils.cpp b/dali/internal/text/text-abstraction/plugin/font-client-utils.cpp index 445e026..2ca3b1c 100644 --- a/dali/internal/text/text-abstraction/plugin/font-client-utils.cpp +++ b/dali/internal/text/text-abstraction/plugin/font-client-utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -131,10 +131,10 @@ const FontSlant::Type IntToSlantType(int slant) return static_cast(ValueToIndex(slant, FONT_SLANT_TYPE_TO_INT, NUM_FONT_SLANT_TYPE - 1u)); } -const std::string DEFAULT_FONT_FAMILY_NAME("Tizen"); -const int DEFAULT_FONT_WIDTH(100); -const int DEFAULT_FONT_WEIGHT(80); -const int DEFAULT_FONT_SLANT(0); +const char* DEFAULT_FONT_FAMILY_NAME("Tizen"); +const int DEFAULT_FONT_WIDTH(100); +const int DEFAULT_FONT_WEIGHT(80); +const int DEFAULT_FONT_SLANT(0); const std::string_view DefaultFontFamily() { diff --git a/dali/internal/window-system/ubuntu-x11/window-base-ecore-x.cpp b/dali/internal/window-system/ubuntu-x11/window-base-ecore-x.cpp index ef2e530..c70bc4b 100644 --- a/dali/internal/window-system/ubuntu-x11/window-base-ecore-x.cpp +++ b/dali/internal/window-system/ubuntu-x11/window-base-ecore-x.cpp @@ -37,7 +37,7 @@ namespace Adaptor { namespace { -const std::string DEFAULT_DEVICE_NAME = ""; +const char* DEFAULT_DEVICE_NAME = ""; const Device::Class::Type DEFAULT_DEVICE_CLASS = Device::Class::NONE; const Device::Subclass::Type DEFAULT_DEVICE_SUBCLASS = Device::Subclass::NONE; diff --git a/dali/internal/window-system/windows/platform-implement-win.cpp b/dali/internal/window-system/windows/platform-implement-win.cpp index 658c64c..2716f90 100644 --- a/dali/internal/window-system/windows/platform-implement-win.cpp +++ b/dali/internal/window-system/windows/platform-implement-win.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2021 Samsung Electronics Co., Ltd. +* Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ LRESULT CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) namespace { -const std::string DALI_WINDOW_CLASS_NAME = "DaliWindow"; +const char* DALI_WINDOW_CLASS_NAME = "DaliWindow"; uint32_t sNumWindows = 0; diff --git a/dali/internal/window-system/x11/window-base-x.cpp b/dali/internal/window-system/x11/window-base-x.cpp index 3f803f7..be48605 100644 --- a/dali/internal/window-system/x11/window-base-x.cpp +++ b/dali/internal/window-system/x11/window-base-x.cpp @@ -39,7 +39,7 @@ namespace Adaptor { namespace { -const std::string DEFAULT_DEVICE_NAME = ""; +const char* DEFAULT_DEVICE_NAME = ""; const Device::Class::Type DEFAULT_DEVICE_CLASS = Device::Class::NONE; const Device::Subclass::Type DEFAULT_DEVICE_SUBCLASS = Device::Subclass::NONE; -- 2.7.4