mirror of https://github.com/BOINC/boinc.git
- client (and anything else using MFILE): Win efficiency fix.
Shockingly, realloc() wasn't doing exponential growth. So create realloc_aux() that does. svn path=/trunk/boinc/; revision=20943
This commit is contained in:
parent
7b204d008e
commit
6449eb1ec4
|
@ -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
|
||||
|
|
|
@ -767,7 +767,7 @@ WORKUNIT* CC_STATE::lookup_wu(PROJECT* project, char* name) {
|
|||
unsigned int i;
|
||||
for (i=0; i<wus.size(); i++) {
|
||||
if (wus[i]->project != 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; i<results.size(); i++) {
|
||||
if (results[i]->project != project) continue;
|
||||
if (strcmp(results[i]->name, name)) return results[i];
|
||||
if (!strcmp(results[i]->name, name)) return results[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue