From 391980ce1e890445542441eeb5d9f9cc18ae1baf Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 26 Jan 2018 22:31:20 +0300 Subject: code optimization --- protocols/VKontakte/src/misc.cpp | 52 +++++++++++++++++------------------ protocols/VKontakte/src/vk_thread.cpp | 6 ++-- 2 files changed, 29 insertions(+), 29 deletions(-) (limited to 'protocols/VKontakte') diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 1169de5b01..95510c591d 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -84,9 +84,9 @@ void InitIcons() HANDLE GetIconHandle(int iCommand) { - for (int i = 0; i < _countof(iconList); i++) - if (iconList[i].defIconID == iCommand) - return iconList[i].hIcolib; + for (auto &it : iconList) + if (it.defIconID == iCommand) + return it.hIcolib; return nullptr; } @@ -847,10 +847,10 @@ CMStringA CVkProto::GetAttachmentsFromMessage(const char *Msg) iOwner = 0, iId = 0; - for (int i = 0; i < _countof(szAttachmentMasks); i++) { - iRes = sscanf(pos, szAttachmentMasks[i], &iOwner, &iId); + for (auto &it : szAttachmentMasks) { + iRes = sscanf(pos, it, &iOwner, &iId); if (iRes == 2) { - CMStringA szAttachment(FORMAT, szAttachmentMasks[i], iOwner, iId); + CMStringA szAttachment(FORMAT, it, iOwner, iId); CMStringA szAttachment2; if (nextpos) @@ -934,11 +934,11 @@ CMStringW CVkProto::SpanVKNotificationType(CMStringW& wszType, VKObjType& vkFeed CMStringW wszRes; vkFeedback = vkParent = vkNull; - for (int i = 0; i < _countof(vkNotification); i++) - if (wszType == vkNotification[i].pwszType) { - vkFeedback = vkNotification[i].vkFeedback; - vkParent = vkNotification[i].vkParent; - wszRes = vkNotification[i].pwszTranslate; + for (auto &it : vkNotification) + if (wszType == it.pwszType) { + vkFeedback = it.vkFeedback; + vkParent = it.vkParent; + wszRes = it.pwszTranslate; break; } return wszRes; @@ -952,8 +952,8 @@ CMStringW CVkProto::GetVkPhotoItem(const JSONNode &jnPhoto, BBCSupport iBBC) return wszRes; CMStringW wszLink, wszPreviewLink; - for (int i = 0; i < _countof(szImageTypes); i++) { - const JSONNode &n = jnPhoto[szImageTypes[i]]; + for (auto &it : szImageTypes) { + const JSONNode &n = jnPhoto[it]; if (n) { wszLink = n.as_mstring(); break; @@ -1022,9 +1022,9 @@ CMStringW CVkProto::SetBBCString(LPCWSTR pwszString, BBCSupport iBBC, VKBBCType return CMStringW(); wchar_t *pwszFormat = nullptr; - for (int i = 0; i < _countof(bbcItem); i++) - if (bbcItem[i].vkBBCType == bbcType && bbcItem[i].vkBBCSettings == iBBC) { - pwszFormat = bbcItem[i].pwszTempate; + for (auto &it : bbcItem) + if (it.vkBBCType == bbcType && it.vkBBCSettings == iBBC) { + pwszFormat = it.pwszTempate; break; } @@ -1178,8 +1178,8 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport } else { CMStringW wszLink; - for (int i = 0; i < _countof(szImageTypes); i++) { - const JSONNode &n = jnSticker[szImageTypes[i]]; + for (auto &it : szImageTypes) { + const JSONNode &n = jnSticker[it]; if (n) { wszLink = n.as_mstring(); break; @@ -1251,8 +1251,8 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport continue; CMStringW wszLink; - for (int i = 0; i < _countof(szGiftTypes); i++) { - const JSONNode &n = jnGift[szGiftTypes[i]]; + for (auto &it : szGiftTypes) { + const JSONNode &n = jnGift[it]; if (n) { wszLink = n.as_mstring(); break; @@ -1397,9 +1397,9 @@ CMStringW CVkProto::RemoveBBC(CMStringW& wszSrc) CMStringW wszLow(wszSrc); wszLow.MakeLower(); - for (int i = 0; i < _countof(wszSimpleBBCodes); i++) { - CMStringW wszOpenTag(wszSimpleBBCodes[i][0]); - CMStringW wszCloseTag(wszSimpleBBCodes[i][1]); + for (auto &it : wszSimpleBBCodes) { + CMStringW wszOpenTag(it[0]); + CMStringW wszCloseTag(it[1]); int lenOpen = wszOpenTag.GetLength(); int lenClose = wszCloseTag.GetLength(); @@ -1423,9 +1423,9 @@ CMStringW CVkProto::RemoveBBC(CMStringW& wszSrc) } } - for (int i = 0; i < _countof(wszParamBBCodes); i++) { - CMStringW wszOpenTag(wszParamBBCodes[i][0]); - CMStringW wszCloseTag(wszParamBBCodes[i][1]); + for (auto &it : wszParamBBCodes) { + CMStringW wszOpenTag(it[0]); + CMStringW wszCloseTag(it[1]); int lenOpen = wszOpenTag.GetLength(); int lenClose = wszCloseTag.GetLength(); diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 4540783d48..a9016dde16 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -458,15 +458,15 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, VKContactTy int iInteres = 0; - for (int i = 0; i < _countof(vkInteres); i++) { - wszValue = jnItem[vkInteres[i].szField].as_mstring(); + for (auto &it : vkInteres) { + wszValue = jnItem[it.szField].as_mstring(); if (wszValue.IsEmpty()) continue; CMStringA InteresCat(FORMAT, "Interest%dCat", iInteres); CMStringA InteresText(FORMAT, "Interest%dText", iInteres); - setWString(hContact, InteresCat, vkInteres[i].pwszTranslate); + setWString(hContact, InteresCat, it.pwszTranslate); setWString(hContact, InteresText, wszValue); iInteres++; -- cgit v1.2.3