From 18849f113e707fc6ed5ccccb684672c82073ced0 Mon Sep 17 00:00:00 2001 From: wj32 Date: Mon, 27 Sep 2010 09:31:43 +0000 Subject: [PATCH] small optimizations git-svn-id: svn://svn.code.sf.net/p/processhacker/code@3685 21ef857c-d57f-4fe0-8362-d861dc6d29cd --- 2.x/trunk/phlib/basesupx.c | 2 +- 2.x/trunk/phlib/support.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/2.x/trunk/phlib/basesupx.c b/2.x/trunk/phlib/basesupx.c index 8c250f6a3..9ab85a87a 100644 --- a/2.x/trunk/phlib/basesupx.c +++ b/2.x/trunk/phlib/basesupx.c @@ -31,8 +31,8 @@ __declspec(naked) int __cdecl ph_equal_string(wchar_t *s1, wchar_t *s2, size_t l push esi push edi - mov eax, [esp+0xc+0x8] // len mov ecx, [esp+0xc+0x8] // len + mov eax, [esp+0xc+0x8] // len and ecx, -2 // round down to even number mov esi, [esp+0xc+0x0] // s1 diff --git a/2.x/trunk/phlib/support.c b/2.x/trunk/phlib/support.c index b028fef2c..20bf70a5b 100644 --- a/2.x/trunk/phlib/support.c +++ b/2.x/trunk/phlib/support.c @@ -1333,6 +1333,7 @@ PPH_STRING PhFormatSize( WCHAR numberString[512]; // perf hack PPH_STRING formattedString; PPH_STRING outputString; + ULONG length; swprintf_s(numberString, sizeof(numberString) / 2, L"%.2f", s); formattedString = PhFormatDecimal(numberString, 2, TRUE); @@ -1342,19 +1343,22 @@ PPH_STRING PhFormatSize( return PhFormatString(L"%.2g %s", s, PhSizeUnitNames[i]); } + length = formattedString->Length / 2; + if ( - PhEndsWithString2(formattedString, L"00", FALSE) && - formattedString->Length >= 6 + length >= 3 && + formattedString->Buffer[length - 1] == '0' && + formattedString->Buffer[length - 2] == '0' ) { // Remove the last three characters by making sure // PhConcatStrings doesn't include them. - formattedString->Buffer[formattedString->Length / 2 - 3] = 0; + formattedString->Buffer[length - 3] = 0; } - else if (PhEndsWithString2(formattedString, L"0", FALSE)) + else if (length >= 1 && formattedString->Buffer[length - 1] == '0') { // Remove the last character. - formattedString->Buffer[formattedString->Length / 2 - 1] = 0; + formattedString->Buffer[length - 1] = 0; } outputString = PhConcatStrings(3, formattedString->Buffer, L" ", PhSizeUnitNames[i]);