X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..refs/heads/master:/icuSources/test/perf/collationperf/collperf.cpp diff --git a/icuSources/test/perf/collationperf/collperf.cpp b/icuSources/test/perf/collationperf/collperf.cpp index a518254d..33e3e6c6 100644 --- a/icuSources/test/perf/collationperf/collperf.cpp +++ b/icuSources/test/perf/collationperf/collperf.cpp @@ -1,8 +1,12 @@ -/******************************************************************** +/*********************************************************************** + * © 2016 and later: Unicode, Inc. and others. + * License & terms of use: http://www.unicode.org/copyright.html#License + *********************************************************************** + *********************************************************************** * COPYRIGHT: - * Copyright (C) 2001-2008 IBM, Inc. All Rights Reserved. + * Copyright (C) 2001-2012 IBM, Inc. All Rights Reserved. * - ********************************************************************/ + ***********************************************************************/ /******************************************************************************** * * File CALLCOLL.C @@ -81,7 +85,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 +93,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 +107,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,9 +372,8 @@ int ICURandomCmp(const void *a, const void *b) { void doKeyGen() { int line; - int loops; + int loops = 0; int iLoop; - int t; int len=-1; // Adjust loop count to compensate for file size. Should be order n @@ -388,9 +391,9 @@ void doKeyGen() len = gFileLines[line].len; } for (iLoop=0; iLoop < opt_iLoopCount; iLoop++) { - t=LCMapStringW(gWinLCID, LCMAP_SORTKEY, + LCMapStringW(gWinLCID, LCMAP_SORTKEY, gFileLines[line].name, len, - (unsigned short *)gFileLines[line].winSortKey, 5000); // TODO something with length. + (UChar *)gFileLines[line].winSortKey, 5000); // TODO something with length. } } } @@ -403,7 +406,7 @@ void doKeyGen() len = gFileLines[line].len; } for (iLoop=0; iLoop < opt_iLoopCount; iLoop++) { - t = ucol_getSortKey(gCol, gFileLines[line].name, len, (unsigned char *)gFileLines[line].icuSortKey, 5000); + ucol_getSortKey(gCol, gFileLines[line].name, len, (unsigned char *)gFileLines[line].icuSortKey, 5000); } } } @@ -413,7 +416,7 @@ void doKeyGen() for (loops=0; loopsicuSortKey, (gSortedLines[guess])->icuSortKey); @@ -574,7 +577,7 @@ void doBinarySearch() if (opt_win) { unsigned long startTime = timeGetTime(); - int r; + int r = 0; for (loops=0; loops= 0x10000) { @@ -1353,6 +1358,10 @@ UChar UCharFile::get() { } break; }; + default: + c = 0xFFFD; /* Error, unspecified codepage*/ + fprintf(stderr, "UCharFile: Error: unknown fEncoding\n"); + exit(1); } return c; } @@ -1371,6 +1380,7 @@ UCollator *openRulesCollator() { int bufLen = 10000; UChar *buf = (UChar *)malloc(bufLen * sizeof(UChar)); + UChar *tmp; int i = 0; for(;;) { @@ -1383,8 +1393,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 +1612,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,8 +1635,8 @@ int main(int argc, const char** argv) { for (line=0; line sizeof(buf)) { - t = LCMapStringW(gWinLCID, LCMAP_SORTKEY, gFileLines[line].name, -1, (unsigned short *)(gFileLines[line].winSortKey), t); + if (t > (int32_t)sizeof(buf)) { + t = LCMapStringW(gWinLCID, LCMAP_SORTKEY, gFileLines[line].name, -1, (UChar *)(gFileLines[line].winSortKey), t); } else { @@ -1636,7 +1651,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