When loading a PYC resource check whether the filename is the

application, and if so take a shortcut. This should speedup loading
PYC resources when running off a CDROM quite a bit.
This commit is contained in:
Jack Jansen 1996-11-09 18:43:44 +00:00
parent 6c06590305
commit 8096daad4f
1 changed files with 45 additions and 21 deletions

View File

@ -579,20 +579,32 @@ char *filename;
int ok; int ok;
Handle h; Handle h;
if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr ) if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) {
return 0; /* It doesn't exist */ /*
if ( FSpGetFInfo(&fss, &finfo) != noErr ) ** Special case: the application itself. Use a shortcut to
return 0; /* shouldn't happen, I guess */ ** forestall opening and closing the application numerous times
oldrh = CurResFile(); ** (which is dead slow when running from CDROM)
filerh = FSpOpenResFile(&fss, fsRdPerm); */
if ( filerh == -1 ) oldrh = CurResFile();
return 0; UseResFile(PyMac_AppRefNum);
UseResFile(filerh); filerh = -1;
} else {
if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr )
return 0; /* It doesn't exist */
if ( FSpGetFInfo(&fss, &finfo) != noErr )
return 0; /* shouldn't happen, I guess */
oldrh = CurResFile();
filerh = FSpOpenResFile(&fss, fsRdPerm);
if ( filerh == -1 )
return 0;
UseResFile(filerh);
}
SetResLoad(0); SetResLoad(0);
h = Get1NamedResource('PYC ', Pstring(module)); h = Get1NamedResource('PYC ', Pstring(module));
SetResLoad(1); SetResLoad(1);
ok = (h != NULL); ok = (h != NULL);
CloseResFile(filerh); if ( filerh != -1 )
CloseResFile(filerh);
UseResFile(oldrh); UseResFile(oldrh);
return ok; return ok;
} }
@ -613,17 +625,28 @@ char *filename;
PyObject *m, *co; PyObject *m, *co;
long num, size; long num, size;
if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr ) if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) {
goto error; /*
if ( (err=FSpGetFInfo(&fss, &finfo)) != noErr ) ** Special case: the application itself. Use a shortcut to
goto error; ** forestall opening and closing the application numerous times
oldrh = CurResFile(); ** (which is dead slow when running from CDROM)
filerh = FSpOpenResFile(&fss, fsRdPerm); */
if ( filerh == -1 ) { oldrh = CurResFile();
err = ResError(); UseResFile(PyMac_AppRefNum);
goto error; filerh = -1;
} else {
if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr )
goto error;
if ( (err=FSpGetFInfo(&fss, &finfo)) != noErr )
goto error;
oldrh = CurResFile();
filerh = FSpOpenResFile(&fss, fsRdPerm);
if ( filerh == -1 ) {
err = ResError();
goto error;
}
UseResFile(filerh);
} }
UseResFile(filerh);
h = Get1NamedResource('PYC ', Pstring(module)); h = Get1NamedResource('PYC ', Pstring(module));
if ( h == NULL ) { if ( h == NULL ) {
err = ResError(); err = ResError();
@ -651,7 +674,8 @@ char *filename;
} }
} }
HUnlock(h); HUnlock(h);
CloseResFile(filerh); if ( filerh != -1 )
CloseResFile(filerh);
UseResFile(oldrh); UseResFile(oldrh);
if ( co ) { if ( co ) {
m = PyImport_ExecCodeModule(module, co); m = PyImport_ExecCodeModule(module, co);