diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2001-05-22 14:13:02 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2001-05-22 14:13:02 (GMT) |
commit | b45032e62924959643676fc0313d866d5336fcc3 (patch) | |
tree | 4c6d1b679808d04a7708c213f752413d61292f34 /Mac | |
parent | aa222234c0836d32030c667240f20d8879e7f6b3 (diff) | |
download | cpython-b45032e62924959643676fc0313d866d5336fcc3.zip cpython-b45032e62924959643676fc0313d866d5336fcc3.tar.gz cpython-b45032e62924959643676fc0313d866d5336fcc3.tar.bz2 |
Fixed a nasty slowdown in imports in frozen applications: the shortcut
for loading modules from the application resource fork stopped working
when sys.path component normalization was implemented. Comparison
of sys.path components is now done by FSSpec in stead of by pathname.
Diffstat (limited to 'Mac')
-rw-r--r-- | Mac/Python/macimport.c | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/Mac/Python/macimport.c b/Mac/Python/macimport.c index b1d6591..1181012 100644 --- a/Mac/Python/macimport.c +++ b/Mac/Python/macimport.c @@ -47,6 +47,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <TextUtils.h> #endif #include <CodeFragments.h> +#include <StringCompare.h> #ifdef USE_GUSI1 #include "TFileSpec.h" /* for Path2FSSpec() */ @@ -55,6 +56,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. typedef void (*dl_funcptr)(); #define FUNCNAME_PATTERN "init%.200s" +static int +fssequal(FSSpec *fs1, FSSpec *fs2) +{ + if ( fs1->vRefNum != fs2->vRefNum || fs1->parID != fs2->parID ) + return 0; + return EqualString(fs1->name, fs2->name, false, true); +} /* ** findnamedresource - Common code for the various *ResourceModule functions. ** Check whether a file contains a resource of the correct name and type, and @@ -93,8 +101,19 @@ findnamedresource( return 0; } #endif /* INTERN_STRINGS */ - - if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) { +#ifdef USE_GUSI1 + if ( Path2FSSpec(filename, &fss) != noErr ) { +#else + if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr ) { +#endif +#ifdef INTERN_STRINGS + if ( obj && max_not_a_file < MAXPATHCOMPONENTS && obj->ob_sinterned ) + not_a_file[max_not_a_file++] = obj; +#endif /* INTERN_STRINGS */ + /* doesn't exist or is folder */ + return 0; + } + if ( fssequal(&fss, &PyMac_ApplicationFSSpec) ) { /* ** Special case: the application itself. Use a shortcut to ** forestall opening and closing the application numerous times @@ -104,19 +123,14 @@ findnamedresource( UseResFile(PyMac_AppRefNum); filerh = -1; } else { -#ifdef USE_GUSI1 - if ( Path2FSSpec(filename, &fss) != noErr || -#else - if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr || -#endif - FSpGetFInfo(&fss, &finfo) != noErr ) { #ifdef INTERN_STRINGS + if ( FSpGetFInfo(&fss, &finfo) != noErr ) { if ( obj && max_not_a_file < MAXPATHCOMPONENTS && obj->ob_sinterned ) not_a_file[max_not_a_file++] = obj; -#endif /* INTERN_STRINGS */ - /* doesn't exist or is folder */ + /* doesn't exist or is folder */ return 0; } +#endif /* INTERN_STRINGS */ oldrh = CurResFile(); filerh = FSpOpenResFile(&fss, fsRdPerm); if ( filerh == -1 ) @@ -293,7 +307,14 @@ char *filename; PyObject *m, *co; long num, size; - if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) { +#ifdef USE_GUSI1 + if ( (err=Path2FSSpec(filename, &fss)) != noErr || + FSpGetFInfo(&fss, &finfo) != noErr ) +#else + if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr ) +#endif + goto error; + if ( fssequal(&fss, &PyMac_ApplicationFSSpec) ) { /* ** Special case: the application itself. Use a shortcut to ** forestall opening and closing the application numerous times @@ -303,13 +324,6 @@ char *filename; UseResFile(PyMac_AppRefNum); filerh = -1; } else { -#ifdef USE_GUSI1 - if ( (err=Path2FSSpec(filename, &fss)) != noErr || - FSpGetFInfo(&fss, &finfo) != noErr ) -#else - if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr ) -#endif - goto error; if ( (err=FSpGetFInfo(&fss, &finfo)) != noErr ) goto error; oldrh = CurResFile(); |