diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1996-11-09 18:43:44 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1996-11-09 18:43:44 (GMT) |
commit | 8096daad4f835fbb8261ebd4dddc61b53cc93779 (patch) | |
tree | cd943e23ad12a5c5c2baca280041e54cfefbeca1 /Mac/Python | |
parent | 6c06590305d60a957eacdb9af02075ced22001cd (diff) | |
download | cpython-8096daad4f835fbb8261ebd4dddc61b53cc93779.zip cpython-8096daad4f835fbb8261ebd4dddc61b53cc93779.tar.gz cpython-8096daad4f835fbb8261ebd4dddc61b53cc93779.tar.bz2 |
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.
Diffstat (limited to 'Mac/Python')
-rw-r--r-- | Mac/Python/macglue.c | 66 |
1 files changed, 45 insertions, 21 deletions
diff --git a/Mac/Python/macglue.c b/Mac/Python/macglue.c index f996f4a..8950020 100644 --- a/Mac/Python/macglue.c +++ b/Mac/Python/macglue.c @@ -579,20 +579,32 @@ char *filename; int ok; Handle h; - 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); + if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) { + /* + ** Special case: the application itself. Use a shortcut to + ** forestall opening and closing the application numerous times + ** (which is dead slow when running from CDROM) + */ + oldrh = CurResFile(); + UseResFile(PyMac_AppRefNum); + 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); h = Get1NamedResource('PYC ', Pstring(module)); SetResLoad(1); ok = (h != NULL); - CloseResFile(filerh); + if ( filerh != -1 ) + CloseResFile(filerh); UseResFile(oldrh); return ok; } @@ -613,17 +625,28 @@ char *filename; PyObject *m, *co; long num, size; - 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; + if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) { + /* + ** Special case: the application itself. Use a shortcut to + ** forestall opening and closing the application numerous times + ** (which is dead slow when running from CDROM) + */ + oldrh = CurResFile(); + UseResFile(PyMac_AppRefNum); + 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)); if ( h == NULL ) { err = ResError(); @@ -651,7 +674,8 @@ char *filename; } } HUnlock(h); - CloseResFile(filerh); + if ( filerh != -1 ) + CloseResFile(filerh); UseResFile(oldrh); if ( co ) { m = PyImport_ExecCodeModule(module, co); |