• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisão7414a4f6abb634fe6135a9f136cb0774e9714f51 (tree)
Hora2012-01-21 00:43:13
AutorMoriguchi, Hirokazu <umorigu@gmai...>
CommiterMoriguchi, Hirokazu

Mensagem de Log

MessageUtil_GetUTF8StaticBinaryBlock: Find key string by bsearch()

Mudança Sumário

Diff

--- a/msgutil.c
+++ b/msgutil.c
@@ -4,7 +4,7 @@
44 /**
55 * アドレス固定のWide文字列とそれに対応するUTF-8文字列を格納する構造体
66 */
7-typedef struct {
7+typedef struct StrPair_ {
88 const wchar_t *ws;
99 char *u8s;
1010 size_t u8size;
@@ -22,6 +22,9 @@ static int strMapCount = 0;
2222 //! 確保済みのStrPairの領域数
2323 static int strMapMaxCount = 0;
2424
25+//! StrPair比較関数
26+static int CompareStrPair(const void *c1, const void *c2);
27+
2528 /**
2629 * staticなWide文字列に対応するUTF-8バイナリ文字列領域を確保し、その先頭アドレスを返す
2730 */
@@ -37,12 +40,13 @@ const char* const MessageUtil_GetUTF8StaticBinaryBlock(const wchar_t* const ws,
3740 g_initialized = TRUE;
3841 }
3942 EnterCriticalSection(&g_msgUtilLLock);
40- for (i = 0; i < strMapCount; i++)
4143 {
42- if (pStrMap[i].ws == ws)
44+ // 二分探索
45+ StrPair keyPair = {ws, NULL};
46+ StrPair *pResultStrPair = bsearch(&keyPair, pStrMap, strMapCount, sizeof(StrPair), CompareStrPair);
47+ if (pResultStrPair)
4348 {
44- pResult = pStrMap[i].u8s;
45- break;
49+ pResult = pResultStrPair->u8s;
4650 }
4751 }
4852 if (pResult == NULL)
@@ -74,6 +78,9 @@ const char* const MessageUtil_GetUTF8StaticBinaryBlock(const wchar_t* const ws,
7478 pStrMap[index].u8s = beginPos;
7579 postSize = WideCharToMultiByte(CP_UTF8, 0, ws, ws_area_length, beginPos, newSize, NULL, NULL);
7680 pResult = beginPos;
81+
82+ // pStrMap ソートする
83+ qsort(pStrMap, strMapCount, sizeof(StrPair), CompareStrPair);
7784 }
7885 else
7986 {
@@ -104,7 +111,15 @@ void MessageUtil_FreeUTF8StaticBinaryBlocks()
104111 if (pStrMap)
105112 {
106113 free(pStrMap);
107- pStrMap = (StrPair*)NULL;
114+ pStrMap = NULL;
108115 }
116+ strMapCount = 0;
109117 LeaveCriticalSection(&g_msgUtilLLock);
110118 }
119+
120+static int CompareStrPair(const void *c1, const void *c2)
121+{
122+ StrPair *p1 = (StrPair*)c1;
123+ StrPair *p2 = (StrPair*)c2;
124+ return p1->ws - p2->ws;
125+}