add specialize_as(), use it to speed up .smali comparison in APKs
Possible fix for #324.
NB: this does not currently take into account the possibility that there could be files that are not text files but do have the extension .smali
in an APK; I've never encountered that before and I see no reason for them to be present, but they could be, theoretically.
To summarise:
- as part of
ApkContainer
,diffoscope
callsapktool
which decompiles the classes in the.dex
files in the APK tosmali{,_classesN}/**/*.smali
files; - these are text files and there are often thousands of them;
- using
libmagic
to identity the file type for all these files (as automatically happens via.recognizes()
) takes minutes; - we know we don't need this identification step (and can safely skip it) since these files are generated by
diffoscope
itself usingapktool
.
This MR:
- splits off
specialize_as()
fromtry_recognize()
to allow us to explicitly specialize a file in those rare cases we need to; - modifies
specialize()
- to perform the
isinstance()
check on allComparatorManager().classes
before running.recognizes()
on any of them (instead of just before calling.recognizes()
on each class in turn); - which IMO makes more sense regardless of also enabling this optimisation (i.e. avoiding use of
libmagic
via.recognizes()
), since currently a file already specialized as aBarFile
would not be returned as-is but turned into aFooFile
as well ifFooFile
is earlier in the list thanBarFile
and.recognizes()
the file;
- to perform the
- uses
specialize_as()
inApkContainer.get_member()
to explicitly specializesmali{,_classesN}/**/*.smali
ArchiveMember
s asTextFile
to avoid thelibmagic
call that is for these specific cases both unnecessary and expensive; - does not affect any other files that happen to have the extension
.smali
or rely on the order ofComparatorManager().classes
.
Edited by FC (Fay) Stegerman