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;
void paintCCItems();
void initVarForm();
void clearCCForm();
void clearCCItems();
public:
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, 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);
~CComponentsForm();
virtual ~CComponentsForm();
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
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,
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 setHeaderText(const std::string& caption);

View File

@@ -1516,15 +1516,19 @@ CComponentsForm::CComponentsForm(const int x_pos, const int y_pos, const int w,
CComponentsForm::~CComponentsForm()
{
#ifdef DEBUG_CC
printf("[CComponents] calling %s...\n", __FUNCTION__);
#endif
hide();
clearSavedScreen();
clearCCForm();
clearCCItems();
clear();
}
void CComponentsForm::clearCCForm()
void CComponentsForm::clearCCItems()
{
for(size_t i=0; i<v_cc_items.size(); i++) {
if (v_cc_items[i])
delete v_cc_items[i];
v_cc_items[i] = NULL;
}
@@ -1664,20 +1668,15 @@ CComponentsHeader::CComponentsHeader( const int x_pos, const int y_pos, const in
cch_icon_name = icon_name;
}
#if 0
CComponentsHeader::~CComponentsHeader()
{
hide();
clearSavedScreen();
clearCCForm();
delete cch_icon_obj;
cch_icon_obj = NULL;
delete cch_text_obj;
cch_text_obj = NULL;
clearCCItems();
clear();
}
#endif
void CComponentsHeader::initVarHeader()
{
@@ -1723,11 +1722,10 @@ void CComponentsHeader::paint(bool do_save_bg)
int cch_items_y = 0;
//clean up first possible old item objects, includes delete and clean up vector
clearCCItems();
//init icon
if (cch_icon_obj){
delete cch_icon_obj;
cch_icon_obj = NULL;
}
int cch_icon_x = 0;
if (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
if (cch_text_obj){
delete cch_text_obj;
cch_text_obj = NULL;
}
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->setTextFont(cch_font);