X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..ef6cf650f4a75c3f97de06b51fa104f2069b9ea2:/icuSources/test/perf/collationperf/collperf.cpp diff --git a/icuSources/test/perf/collationperf/collperf.cpp b/icuSources/test/perf/collationperf/collperf.cpp index a518254d..1ce07817 100644 --- a/icuSources/test/perf/collationperf/collperf.cpp +++ b/icuSources/test/perf/collationperf/collperf.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (C) 2001-2008 IBM, Inc. All Rights Reserved. + * Copyright (C) 2001-2012 IBM, Inc. All Rights Reserved. * ********************************************************************/ /******************************************************************************** @@ -81,7 +81,7 @@ const char gUsageString[] = // Stubs for Windows API functions when building on UNIXes. // typedef int DWORD; -inline int CompareStringW(DWORD, DWORD, UChar *, int, UChar *, int) {return 0;}; +inline int CompareStringW(DWORD, DWORD, UChar *, int, UChar *, int) {return 0;} #include unsigned long timeGetTime() { struct timeval t; @@ -89,8 +89,8 @@ unsigned long timeGetTime() { unsigned long val = t.tv_sec * 1000; // Let it overflow. Who cares. val += t.tv_usec / 1000; return val; -}; -inline int LCMapStringW(DWORD, DWORD, UChar *, int, UChar *, int) {return 0;}; +} +inline int LCMapStringW(DWORD, DWORD, UChar *, int, UChar *, int) {return 0;} const int LCMAP_SORTKEY = 0; #define MAKELCID(a,b) 0 const int SORT_DEFAULT = 0; @@ -103,7 +103,7 @@ const int SORT_DEFAULT = 0; // These global variables are set according to the options specified // on the command line by the user. char * opt_fName = 0; -char * opt_locale = "en_US"; +const char * opt_locale = "en_US"; int opt_langid = 0; // Defaults to value corresponding to opt_locale. char * opt_rules = 0; UBool opt_help = FALSE; @@ -368,7 +368,7 @@ int ICURandomCmp(const void *a, const void *b) { void doKeyGen() { int line; - int loops; + int loops = 0; int iLoop; int t; int len=-1; @@ -465,15 +465,15 @@ void doBinarySearch() gCount = 0; int line; - int loops; - int iLoop; - unsigned long elapsedTime; + int loops = 0; + int iLoop = 0; + unsigned long elapsedTime = 0; // Adjust loop count to compensate for file size. Should be order n (lookups) * log n (compares/lookup) // Accurate timings do not depend on this being perfect. The correction is just to try to // get total running times of about the right order, so the that user doesn't need to // manually adjust the loop count for every different file size. - double dLoopCount = double(opt_loopCount) * 3000. / (log10(gNumFileLines) * double(gNumFileLines)); + double dLoopCount = double(opt_loopCount) * 3000. / (log10((double)gNumFileLines) * double(gNumFileLines)); if (opt_usekeys) dLoopCount *= 5; int adj_loopCount = int(dLoopCount); if (adj_loopCount < 1) adj_loopCount = 1; @@ -490,7 +490,7 @@ void doBinarySearch() //if (opt_strcmp && opt_win) {pf = (PF)wcscmp;} // Damn the difference between int32_t and int // which forces the use of a cast here. - int r; + int r = 0; for (loops=0; loopsicuSortKey, (gSortedLines[guess])->icuSortKey); @@ -574,7 +574,7 @@ void doBinarySearch() if (opt_win) { unsigned long startTime = timeGetTime(); - int r; + int r = 0; for (loops=0; loops= 0x10000) { @@ -1353,6 +1355,10 @@ UChar UCharFile::get() { } break; }; + default: + c = 0xFFFD; /* Error, unspecified codepage*/ + fprintf(stderr, "UCharFile: Error: unknown fEncoding\n"); + exit(1); } return c; } @@ -1371,6 +1377,7 @@ UCollator *openRulesCollator() { int bufLen = 10000; UChar *buf = (UChar *)malloc(bufLen * sizeof(UChar)); + UChar *tmp; int i = 0; for(;;) { @@ -1383,8 +1390,13 @@ UCollator *openRulesCollator() { } i++; if (i >= bufLen) { + tmp = buf; bufLen += 10000; buf = (UChar *)realloc(buf, bufLen); + if (buf == NULL) { + free(tmp); + return 0; + } } } buf[i] = 0; @@ -1597,13 +1609,13 @@ int main(int argc, const char** argv) { // Pre-compute ICU sort keys for the lines of the file. // int line; - int t; + int32_t t; for (line=0; line sizeof(buf)) { + if (t > (int32_t)sizeof(buf)) { t = ucol_getSortKey(gCol, gFileLines[line].name, -1, (unsigned char *)gFileLines[line].icuSortKey , t); } else @@ -1620,7 +1632,7 @@ int main(int argc, const char** argv) { for (line=0; line sizeof(buf)) { + if (t > (int32_t)sizeof(buf)) { t = LCMapStringW(gWinLCID, LCMAP_SORTKEY, gFileLines[line].name, -1, (unsigned short *)(gFileLines[line].winSortKey), t); } else @@ -1636,7 +1648,7 @@ int main(int argc, const char** argv) { for (line=0; line sizeof(buf)) { + if (t > (int32_t)sizeof(buf)) { t = strxfrm(gFileLines[line].unixSortKey, gFileLines[line].unixName, sizeof(buf)); } else