diff --git a/checkin_notes b/checkin_notes index 2ade362ec7..e1d2b7bb79 100644 --- a/checkin_notes +++ b/checkin_notes @@ -2001,3 +2001,12 @@ Charlie 18 Mar 2010 BOINCGUIApp.cpp lib/ gui_rpc_client_ops.cpp + +David 18 Mar 2010 + - client (and anything else using MFILE): Win efficiency fix. + Shockingly, realloc() wasn't doing exponential growth. + So create realloc_aux() that does. + + lib/ + mfile.cpp + gui_rpc_client_ops.cpp diff --git a/lib/gui_rpc_client_ops.cpp b/lib/gui_rpc_client_ops.cpp index a8a250948e..03dbf46eab 100644 --- a/lib/gui_rpc_client_ops.cpp +++ b/lib/gui_rpc_client_ops.cpp @@ -767,7 +767,7 @@ WORKUNIT* CC_STATE::lookup_wu(PROJECT* project, char* name) { unsigned int i; for (i=0; iproject != project) continue; - if (strcmp(wus[i]->name, name)) return wus[i]; + if (!strcmp(wus[i]->name, name)) return wus[i]; } return 0; } @@ -776,7 +776,7 @@ RESULT* CC_STATE::lookup_result(PROJECT* project, char* name) { unsigned int i; for (i=0; iproject != project) continue; - if (strcmp(results[i]->name, name)) return results[i]; + if (!strcmp(results[i]->name, name)) return results[i]; } return 0; } diff --git a/lib/mfile.cpp b/lib/mfile.cpp index 360b13d1fd..d6fed85187 100644 --- a/lib/mfile.cpp +++ b/lib/mfile.cpp @@ -40,7 +40,7 @@ MFILE::MFILE() { - buf = 0; + buf = (char*)malloc(64*1024); len = 0; } @@ -54,6 +54,13 @@ int MFILE::open(const char* path, const char* mode) { return 0; } +// seems like Win's realloc is stupid, Make it smart. +// +static inline char* realloc_aux(char* p, int len) { + if (_msize(p) >= len) return p; + return (char*) realloc(p, len*2); +} + #define BUFSIZE 100000 int MFILE::vprintf(const char* format, va_list ap) { @@ -68,7 +75,7 @@ int MFILE::vprintf(const char* format, va_list ap) { return -1; } n = (int)strlen(buf2); - buf = (char*)realloc(buf, len+n+1); + buf = (char*)realloc_aux(buf, len+n+1); if (!buf) { fprintf(stderr, "ERROR: realloc() failed in MFILE::vprintf()\n"); exit(1); @@ -90,7 +97,7 @@ int MFILE::printf(const char* format, ...) { } size_t MFILE::write(const void *ptr, size_t size, size_t nitems) { - buf = (char *)realloc( buf, len+(size*nitems)+1 ); + buf = (char *)realloc_aux( buf, len+(size*nitems)+1 ); if (!buf) { fprintf(stderr, "ERROR: realloc() failed in MFILE::write()\n"); exit(1); @@ -102,7 +109,7 @@ size_t MFILE::write(const void *ptr, size_t size, size_t nitems) { } int MFILE::_putchar(char c) { - buf = (char*)realloc(buf, len+1+1); + buf = (char*)realloc_aux(buf, len+1+1); if (!buf) { fprintf(stderr, "ERROR: realloc() failed in MFILE::_putchar()\n"); exit(1); @@ -115,7 +122,7 @@ int MFILE::_putchar(char c) { int MFILE::puts(const char* p) { int n = (int)strlen(p); - buf = (char*)realloc(buf, len+n+1); + buf = (char*)realloc_aux(buf, len+n+1); if (!buf) { fprintf(stderr, "ERROR: realloc() failed in MFILE::puts()\n"); exit(1);