Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8096daa

Browse files
committed
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.
1 parent 6c06590 commit 8096daa

1 file changed

Lines changed: 45 additions & 21 deletions

File tree

Mac/Python/macglue.c

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -579,20 +579,32 @@ char *filename;
579579
int ok;
580580
Handle h;
581581

582-
if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr )
583-
return 0; /* It doesn't exist */
584-
if ( FSpGetFInfo(&fss, &finfo) != noErr )
585-
return 0; /* shouldn't happen, I guess */
586-
oldrh = CurResFile();
587-
filerh = FSpOpenResFile(&fss, fsRdPerm);
588-
if ( filerh == -1 )
589-
return 0;
590-
UseResFile(filerh);
582+
if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) {
583+
/*
584+
** Special case: the application itself. Use a shortcut to
585+
** forestall opening and closing the application numerous times
586+
** (which is dead slow when running from CDROM)
587+
*/
588+
oldrh = CurResFile();
589+
UseResFile(PyMac_AppRefNum);
590+
filerh = -1;
591+
} else {
592+
if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr )
593+
return 0; /* It doesn't exist */
594+
if ( FSpGetFInfo(&fss, &finfo) != noErr )
595+
return 0; /* shouldn't happen, I guess */
596+
oldrh = CurResFile();
597+
filerh = FSpOpenResFile(&fss, fsRdPerm);
598+
if ( filerh == -1 )
599+
return 0;
600+
UseResFile(filerh);
601+
}
591602
SetResLoad(0);
592603
h = Get1NamedResource('PYC ', Pstring(module));
593604
SetResLoad(1);
594605
ok = (h != NULL);
595-
CloseResFile(filerh);
606+
if ( filerh != -1 )
607+
CloseResFile(filerh);
596608
UseResFile(oldrh);
597609
return ok;
598610
}
@@ -613,17 +625,28 @@ char *filename;
613625
PyObject *m, *co;
614626
long num, size;
615627

616-
if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr )
617-
goto error;
618-
if ( (err=FSpGetFInfo(&fss, &finfo)) != noErr )
619-
goto error;
620-
oldrh = CurResFile();
621-
filerh = FSpOpenResFile(&fss, fsRdPerm);
622-
if ( filerh == -1 ) {
623-
err = ResError();
624-
goto error;
628+
if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) {
629+
/*
630+
** Special case: the application itself. Use a shortcut to
631+
** forestall opening and closing the application numerous times
632+
** (which is dead slow when running from CDROM)
633+
*/
634+
oldrh = CurResFile();
635+
UseResFile(PyMac_AppRefNum);
636+
filerh = -1;
637+
} else {
638+
if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr )
639+
goto error;
640+
if ( (err=FSpGetFInfo(&fss, &finfo)) != noErr )
641+
goto error;
642+
oldrh = CurResFile();
643+
filerh = FSpOpenResFile(&fss, fsRdPerm);
644+
if ( filerh == -1 ) {
645+
err = ResError();
646+
goto error;
647+
}
648+
UseResFile(filerh);
625649
}
626-
UseResFile(filerh);
627650
h = Get1NamedResource('PYC ', Pstring(module));
628651
if ( h == NULL ) {
629652
err = ResError();
@@ -651,7 +674,8 @@ char *filename;
651674
}
652675
}
653676
HUnlock(h);
654-
CloseResFile(filerh);
677+
if ( filerh != -1 )
678+
CloseResFile(filerh);
655679
UseResFile(oldrh);
656680
if ( co ) {
657681
m = PyImport_ExecCodeModule(module, co);

0 commit comments

Comments
 (0)