CComponentsHeader: optimize allocations an deallocations for cc-items

Bequeath of destructor from CComponentsForm into CCcomponentsHeader.
clearCCItems() does already manage deallocations for cc-items,
so some 'delete" calls are unnecessary.
There was also the danger to overfill the cc-item vector with new added
objects, if it is not have been cleaned previously in existing instances.
This commit is contained in:
2012-11-07 23:17:34 +01:00
parent e4c4a33477
commit 1934ceef69
2 changed files with 17 additions and 23 deletions

View File

@@ -428,14 +428,14 @@ class CComponentsForm : public CComponentsItem
std::vector<CComponentsItem*> v_cc_items; std::vector<CComponentsItem*> v_cc_items;
void paintCCItems(); void paintCCItems();
void initVarForm(); void initVarForm();
void clearCCForm(); void clearCCItems();
public: public:
CComponentsForm(); CComponentsForm();
CComponentsForm(const int x_pos, const int y_pos, const int w, const int h); CComponentsForm(const int x_pos, const int y_pos, const int w, const int h);
CComponentsForm(const int x_pos, const int y_pos, const int w, const int h, bool has_shadow = CC_SHADOW_OFF, CComponentsForm(const int x_pos, const int y_pos, const int w, const int h, bool has_shadow = CC_SHADOW_OFF,
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUCONTENT_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUCONTENT_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
~CComponentsForm(); virtual ~CComponentsForm();
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
void hide(bool no_restore = false); void hide(bool no_restore = false);
@@ -462,7 +462,7 @@ class CComponentsHeader : public CComponentsForm
CComponentsHeader(const int x_pos, const int y_pos, const int w, const int h = 0, neutrino_locale_t caption_locale = NONEXISTANT_LOCALE, const char* icon_name = NULL, bool has_shadow = CC_SHADOW_OFF, CComponentsHeader(const int x_pos, const int y_pos, const int w, const int h = 0, neutrino_locale_t caption_locale = NONEXISTANT_LOCALE, const char* icon_name = NULL, bool has_shadow = CC_SHADOW_OFF,
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
~CComponentsHeader(); // ~CComponentsHeader();
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
void setHeaderText(const std::string& caption); void setHeaderText(const std::string& caption);

View File

@@ -1516,16 +1516,20 @@ CComponentsForm::CComponentsForm(const int x_pos, const int y_pos, const int w,
CComponentsForm::~CComponentsForm() CComponentsForm::~CComponentsForm()
{ {
#ifdef DEBUG_CC
printf("[CComponents] calling %s...\n", __FUNCTION__);
#endif
hide(); hide();
clearSavedScreen(); clearSavedScreen();
clearCCForm(); clearCCItems();
clear(); clear();
} }
void CComponentsForm::clearCCForm() void CComponentsForm::clearCCItems()
{ {
for(size_t i=0; i<v_cc_items.size(); i++) { for(size_t i=0; i<v_cc_items.size(); i++) {
delete v_cc_items[i]; if (v_cc_items[i])
delete v_cc_items[i];
v_cc_items[i] = NULL; v_cc_items[i] = NULL;
} }
v_cc_items.clear(); v_cc_items.clear();
@@ -1664,20 +1668,15 @@ CComponentsHeader::CComponentsHeader( const int x_pos, const int y_pos, const in
cch_icon_name = icon_name; cch_icon_name = icon_name;
} }
#if 0
CComponentsHeader::~CComponentsHeader() CComponentsHeader::~CComponentsHeader()
{ {
hide(); hide();
clearSavedScreen(); clearSavedScreen();
clearCCForm(); clearCCItems();
delete cch_icon_obj;
cch_icon_obj = NULL;
delete cch_text_obj;
cch_text_obj = NULL;
clear(); clear();
} }
#endif
void CComponentsHeader::initVarHeader() void CComponentsHeader::initVarHeader()
{ {
@@ -1722,12 +1721,11 @@ void CComponentsHeader::paint(bool do_save_bg)
paintInit(do_save_bg); paintInit(do_save_bg);
int cch_items_y = 0; int cch_items_y = 0;
//clean up first possible old item objects, includes delete and clean up vector
clearCCItems();
//init icon //init icon
if (cch_icon_obj){
delete cch_icon_obj;
cch_icon_obj = NULL;
}
int cch_icon_x = 0; int cch_icon_x = 0;
if (cch_icon_name) if (cch_icon_name)
cch_icon_obj = new CComponentsPicture(cch_icon_x, cch_items_y, 0, 0, cch_icon_name); cch_icon_obj = new CComponentsPicture(cch_icon_x, cch_items_y, 0, 0, cch_icon_name);
@@ -1747,10 +1745,6 @@ void CComponentsHeader::paint(bool do_save_bg)
//init text //init text
if (cch_text_obj){
delete cch_text_obj;
cch_text_obj = NULL;
}
int cch_text_x = cch_icon_x+cch_icon_obj->getWidth(); int cch_text_x = cch_icon_x+cch_icon_obj->getWidth();
cch_text_obj = new CComponentsText(cch_text_x, cch_items_y, width-cch_icon_obj->getWidth()-fr_thickness, height-2*fr_thickness, cch_text.c_str()); cch_text_obj = new CComponentsText(cch_text_x, cch_items_y, width-cch_icon_obj->getWidth()-fr_thickness, height-2*fr_thickness, cch_text.c_str());
cch_text_obj->setTextFont(cch_font); cch_text_obj->setTextFont(cch_font);
@@ -1760,7 +1754,7 @@ void CComponentsHeader::paint(bool do_save_bg)
//corner of text item //corner of text item
cch_text_obj->setCornerRadius(corner_rad-fr_thickness); cch_text_obj->setCornerRadius(corner_rad-fr_thickness);
cch_text_obj->setCornerType(corner_type); cch_text_obj->setCornerType(corner_type);
//add elements //add elements
addCCItem(cch_icon_obj); addCCItem(cch_icon_obj);
addCCItem(cch_text_obj); addCCItem(cch_text_obj);