From 420403dedffee8a10336e450337d30e1f25336b2 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Sat, 4 Jun 2016 13:09:01 +0000 Subject: code optimization git-svn-id: http://svn.miranda-ng.org/main/trunk@16912 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- include/m_core.h | 56 +++++++++++++++----------------------------------- include/m_system_cpp.h | 11 ++++++---- 2 files changed, 24 insertions(+), 43 deletions(-) diff --git a/include/m_core.h b/include/m_core.h index 07ffec3156..634a864708 100644 --- a/include/m_core.h +++ b/include/m_core.h @@ -529,32 +529,27 @@ MIR_CORE_DLL(wchar_t*) mir_a2u(const char* src); MIR_CORE_DLL(char*) mir_u2a_cp(const wchar_t* src, int codepage); MIR_CORE_DLL(char*) mir_u2a(const wchar_t* src); -#if defined(__cplusplus) +#ifdef __cplusplus -class _A2T +#ifndef M_SYSTEM_CPP_H__ +extern "C++" { - TCHAR* buf; +#include +} +#endif +class _A2T : public ptrT +{ public: - __forceinline _A2T(const char* s) : buf(mir_a2t(s)) {} - __forceinline _A2T(const char* s, int cp) : buf(mir_a2t_cp(s, cp)) {} - ~_A2T() { mir_free(buf); } - - __forceinline operator LPARAM() const { return (LPARAM)buf; } - __forceinline operator TCHAR*() const { return buf; } + __inline _A2T(const char* s) : ptrT(mir_a2t(s)) {} + __inline _A2T(const char* s, int cp) : ptrT(mir_a2t_cp(s, cp)) {} }; -class _T2A +class _T2A : public ptrA { - char* buf; - public: - __forceinline _T2A(const TCHAR* s) : buf(mir_t2a(s)) {} - __forceinline _T2A(const TCHAR* s, int cp) : buf(mir_t2a_cp(s, cp)) {} - __forceinline ~_T2A() { mir_free(buf); } - - __forceinline operator LPARAM() const { return (LPARAM)buf; } - __forceinline operator char*() const { return buf; } + __forceinline _T2A(const TCHAR* s) : ptrA(mir_t2a(s)) {} + __forceinline _T2A(const TCHAR* s, int cp) : ptrA(mir_t2a_cp(s, cp)) {} }; #endif @@ -631,30 +626,13 @@ __forceinline char* mir_utf8decodeA(const char* src) #define mir_utf8encodeT mir_utf8encode #endif -class T2Utf +class T2Utf : public ptrA { - char* m_str; - public: - __forceinline T2Utf(const TCHAR *str) : - m_str(mir_utf8encodeT(str)) - {} - - __forceinline ~T2Utf() - { mir_free(m_str); - } - - __forceinline char* detach() - { char *res = m_str; m_str = NULL; - return res; - } - - __forceinline char& operator[](size_t idx) const { return m_str[idx]; } - __forceinline operator char*() const { return m_str; } - __forceinline operator unsigned char*() const { return (unsigned char*)m_str; } - __forceinline operator LPARAM() const { return (LPARAM)m_str; } + __forceinline T2Utf(const TCHAR *str) : ptrA(mir_utf8encodeT(str)) {} + __forceinline operator BYTE* () const { return (BYTE*)data; } #ifdef _XSTRING_ - std::string str() const { return std::string(m_str); } + std::string str() const { return std::string(data); } #endif }; diff --git a/include/m_system_cpp.h b/include/m_system_cpp.h index 9ef15830bc..32c26db65c 100644 --- a/include/m_system_cpp.h +++ b/include/m_system_cpp.h @@ -21,6 +21,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + #ifndef M_SYSTEM_CPP_H__ #define M_SYSTEM_CPP_H__ 1 @@ -42,12 +43,14 @@ namespace std template class mir_ptr { +protected: T* data; public: __inline explicit mir_ptr() : data(NULL) {} __inline explicit mir_ptr(T* _p) : data(_p) {} __inline ~mir_ptr() { mir_free(data); } + __inline T* get() const { return data; } __inline T* operator = (T* _p) { if (data) mir_free(data); data = _p; return data; } __inline T* operator->() const { return data; } __inline operator T*() const { return data; } @@ -97,8 +100,8 @@ public: __inline ~pass_ptrA() { zero(); } __inline char* operator = (char *_p){ zero(); return mir_ptr::operator=(_p); } __inline void zero() - { char *_data = mir_ptr::operator char *(); - if (_data) SecureZeroMemory(_data, mir_strlen(_data)); + { + if (data) SecureZeroMemory(data, mir_strlen(data)); } }; @@ -110,8 +113,8 @@ public: __inline ~pass_ptrW() { zero(); } __inline WCHAR* operator = (WCHAR *_p){ zero(); return mir_ptr::operator=(_p); } __inline void zero() - { WCHAR *_data = mir_ptr::operator WCHAR *(); - if (_data) SecureZeroMemory(_data, mir_wstrlen(_data)*sizeof(WCHAR)); + { + if (data) SecureZeroMemory(data, mir_wstrlen(data)*sizeof(WCHAR)); } }; -- cgit v1.2.3