Skip to content

Commit

Permalink
Optimizing Performance
Browse files Browse the repository at this point in the history
  • Loading branch information
cinience committed Dec 26, 2014
1 parent 07d369d commit 56f6b81
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 103 deletions.
130 changes: 105 additions & 25 deletions DuiLib/Control/UITreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,28 +232,91 @@ namespace DuiLib
//************************************
bool CTreeNodeUI::AddAt( CControlUI* pControl, int iIndex )
{
if(NULL == static_cast<CTreeNodeUI*>(pControl->GetInterface(_T("TreeNode"))))
return false;
if (!pControl)
return false;

CTreeNodeUI* pIndexNode = static_cast<CTreeNodeUI*>(mTreeNodes.GetAt(iIndex));
if(!pIndexNode){
if(!mTreeNodes.Add(pControl))
return false;
if(_tcsicmp(pControl->GetClass(), _T("TreeNodeUI")) != 0)
return false;

if (!GetFolderButton()->IsSelected()) //add by:Redrain 2014.8.8
{
m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMDBCLICK);
}
else if(pIndexNode && !mTreeNodes.InsertAt(iIndex,pControl))
return false;

if(!pIndexNode && pTreeView && pTreeView->GetItemAt(GetTreeIndex()+1))
pIndexNode = static_cast<CTreeNodeUI*>(pTreeView->GetItemAt(GetTreeIndex()+1)->GetInterface(_T("TreeNode")));
//filter invalidate index
int iDestIndex = iIndex;
if (iDestIndex < 0)
{
iDestIndex = 0;
}
else if (iDestIndex > GetCountChild())
{
iDestIndex = GetCountChild();
}
if(iIndex != iDestIndex) iIndex = iDestIndex;

pControl = CalLocation((CTreeNodeUI*)pControl);
CTreeNodeUI* pIndexNode = static_cast<CTreeNodeUI*>(mTreeNodes.GetAt(iIndex));

if(pTreeView && pIndexNode)
return pTreeView->AddAt((CTreeNodeUI*)pControl,pIndexNode);
else
return pTreeView->Add((CTreeNodeUI*)pControl);
pControl = CalLocation((CTreeNodeUI*)pControl);

return true;
bool bRet = false;
int iTreeIndex = -1;
if (pTreeView)
{
//Get TreeView insert index
if (pIndexNode)
{
iTreeIndex = pIndexNode->GetTreeIndex();
bRet = pTreeView->AddAt((CTreeNodeUI*)pControl, iTreeIndex) >= 0;
if (bRet)
{
mTreeNodes.InsertAt(iIndex, pControl);
}
}
else
{
CTreeNodeUI *pChildNode = NULL;
//insert child node position index(new node insert to tail, default add tail)
int iChIndex = -1;
//insert child node tree-view position index(new node insert to tail)
int iChTreeIndex = -1;
//search tree index reverse
for (int i = GetCountChild(); i > 0; i++)
{
pChildNode = GetChildNode(i - 1);
iChTreeIndex = pChildNode->GetTreeIndex();
if (iChTreeIndex >= GetTreeIndex() && iChTreeIndex <= GetTreeIndex() + GetCountChild() )
{
//new child node position
iChIndex = i;
//child node tree position
iTreeIndex = iChTreeIndex + 1;
break;
}
}
//child not find tree index directly insert to parent tail
if (iTreeIndex <= GetTreeIndex())
{
iTreeIndex = GetTreeIndex() + 1;
}
//insert TreeNode to TreeView
bRet = pTreeView->AddAt((CTreeNodeUI*)pControl, iTreeIndex) >= 0;
//insert TreeNode to parent TreeNode
if (bRet)
{
if (iChIndex > 0)
bRet = mTreeNodes.InsertAt(iChIndex, pControl);
else
bRet = mTreeNodes.Add(pControl);
}
}
}
else
{
//parent TreeNode not bind TreeView just insert to parent TreeNode
bRet = mTreeNodes.InsertAt(iIndex, pControl);
}
return bRet;
}

//************************************
Expand Down Expand Up @@ -354,6 +417,10 @@ namespace DuiLib
if (_tcsicmp(_pTreeNodeUI->GetClass(), _T("TreeNodeUI")) != 0)
return false;

if (!GetFolderButton()->IsSelected()) //add by:Redrain 2014.8.8
{
m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMDBCLICK);
}
_pTreeNodeUI = CalLocation(_pTreeNodeUI);

bool nRet = true;
Expand Down Expand Up @@ -792,8 +859,8 @@ namespace DuiLib
pControl->GetFolderButton()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnFolderChanged);
pControl->GetCheckBox()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnCheckBoxChanged);

pControl->SetVisibleFolderBtn(m_bVisibleFolderBtn);
pControl->SetVisibleCheckBtn(m_bVisibleCheckBtn);
pControl->SetVisibleFolderBtn(m_bVisibleFolderBtn);
if(m_uItemMinWidth > 0)
pControl->SetMinWidth(m_uItemMinWidth);

Expand All @@ -809,6 +876,7 @@ namespace DuiLib
Add(pNode);
}
}
else

pControl->SetTreeView(this);
return true;
Expand All @@ -829,16 +897,29 @@ namespace DuiLib
if (_tcsicmp(pControl->GetClass(), _T("TreeNodeUI")) != 0)
return -1;

CTreeNodeUI* pParent = static_cast<CTreeNodeUI*>(GetItemAt(iIndex - 1));
if(!pParent)
return -1;
//filter invalidate index
int iDestIndex = iIndex;
if (iDestIndex < 0)
{
iDestIndex = 0;
}
else if (iDestIndex > GetCount())
{
iDestIndex = GetCount();
}
if(iIndex != iDestIndex) iIndex = iDestIndex;

//CTreeNodeUI* pParent = static_cast<CTreeNodeUI*>(GetItemAt(iIndex));
//if(!pParent)
// return -1;

pControl->OnNotify += MakeDelegate(this,&CTreeViewUI::OnDBClickItem);
pControl->GetFolderButton()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnFolderChanged);
pControl->GetCheckBox()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnCheckBoxChanged);

pControl->SetVisibleFolderBtn(m_bVisibleFolderBtn);
pControl->SetVisibleCheckBtn(m_bVisibleCheckBtn);
pControl->SetTreeView(this);

if(m_uItemMinWidth > 0)
pControl->SetMinWidth(m_uItemMinWidth);
Expand All @@ -852,13 +933,12 @@ namespace DuiLib
{
CTreeNodeUI* pNode = pControl->GetChildNode(nIndex);
if(pNode)
return AddAt(pNode,iIndex+1);
{
iIndex = AddAt(pNode, iIndex +1);
}
}
}
else
return iIndex+1;

return -1;
return iIndex;
}

//************************************
Expand Down
27 changes: 17 additions & 10 deletions RedisStudio/Redis/RedisClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ RedisClient::~RedisClient()

}


RedisClient& RedisClient::GetInstance()
{
static RedisClient client;
Expand Down Expand Up @@ -98,13 +97,13 @@ bool RedisClient::Info(std::string& results)
return retVal;
}

bool RedisClient::keys(TSeqArrayResults& results)
bool RedisClient::keys(const std::string& matchstr, TSeqArrayResults& results)
{
bool retVal = false;

if (!IsConnected()) return retVal;

redisReply* reply = Command("KEYS *");
redisReply* reply = Command("KEYS %s", matchstr.c_str());
if (!reply) return retVal;

if (reply->type == REDIS_REPLY_ARRAY)
Expand Down Expand Up @@ -147,15 +146,12 @@ bool RedisClient::Type(const std::string& key, string& type)

long long RedisClient::TTL(const std::string& key)
{
bool retVal = false;
long long ttl = 0;
redisReply* reply = Command("TTL %s", key.c_str());
if (!reply) return ttl;
if (reply->type == REDIS_REPLY_INTEGER)
long long ttl = 0;
ScopedRedisReply reply(Command("TTL %s", key.c_str()));
if (!reply.IsNull() && reply->type == REDIS_REPLY_INTEGER)
{
ttl = reply->integer;
ttl = reply->integer;
}
freeReplyObject(reply);
return ttl;
}

Expand Down Expand Up @@ -255,6 +251,17 @@ bool RedisClient::SelectDB( int dbindex )
return true;
}

long long RedisClient::DbSize()
{
long long dbsize = 0;
ScopedRedisReply reply(Command("DBSIZE"));
if (!reply.IsNull() && reply->type == REDIS_REPLY_INTEGER)
{
dbsize = reply->integer;
}
return dbsize;
}

bool RedisClient::GetConfig(TDicConfig& dicConfig)
{
dicConfig.clear();
Expand Down
7 changes: 5 additions & 2 deletions RedisStudio/Redis/RedisClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef void (* callback)(const CDuiString& );

class RedisResult;

/// ¶ñÐĵĵ¥Àý£¬ÓпÕÖع¹
class RedisClient
{
public:
Expand All @@ -38,20 +39,22 @@ class RedisClient

bool Info(std::string& results);

bool keys(TSeqArrayResults& results);
bool keys(const std::string &, TSeqArrayResults& results);

bool Exists(const std::string& key);

bool Type(const std::string& key, string& type);

long long TTL(const std::string& key);
long long TTL(const std::string& key);

bool DatabasesNum(int& num);

int DatabasesNum();

bool SelectDB(int dbindex);

long long DbSize();

bool GetConfig(TDicConfig& dicConfig);

bool SetConfig(const TDicConfig& dicConfig);
Expand Down
Loading

0 comments on commit 56f6b81

Please sign in to comment.