[m-rev.] Re: for review: speed up make_file_name

Peter Wang novalazy at gmail.com
Wed Jun 25 12:46:14 AEST 2008


Anyone?

On 2008-02-27, Peter Wang <novalazy at gmail.com> wrote:
> Estimated hours taken: 1
> Branches: main
> 
> Speed up the `make_file_name' routine, mainly so `mmc --make' will run faster
> in debugging grades.
> 
> library/dir.m:
> 	Add a predicate to make a relative path name from a list of
> 	components, assuming the components don't contain directory separators.
> 	This requires much less work than `dir./'.
> 
> compiler/modules.m:
> 	Use `relative_path_name_from_components' in `make_file_name' instead of
> 	calls to `dir./'.
> 
> NEWS:
> 	Mention `dir.relative_path_name_from_components'.
> 
> Index: NEWS
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
> retrieving revision 1.487
> diff -u -r1.487 NEWS
> --- NEWS	15 Feb 2008 02:26:48 -0000	1.487
> +++ NEWS	27 Feb 2008 05:21:17 -0000
> @@ -202,7 +202,8 @@
>  * We have added a predicate io.remove_file_recursively/4
>    which can remove non-empty directories.
>  
> -* We have added the predicate `dir.current_directory'.
> +* We have added the predicates `dir.current_directory',
> +  `dir.relative_path_name_from_components'.
>  
>  * We have added the predicates split_last, get_first and get_last to the cord
>    module.
> Index: compiler/modules.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/modules.m,v
> retrieving revision 1.445
> diff -u -r1.445 modules.m
> --- compiler/modules.m	15 Feb 2008 08:31:59 -0000	1.445
> +++ compiler/modules.m	27 Feb 2008 05:21:17 -0000
> @@ -1204,17 +1204,19 @@
>          % Mercury/<grade>/<fullarch>' to find the local `.opt' and `.mih'
>          % files without messing up the search for the files for installed
>          % libraries.
> -        DirName = "Mercury"/Grade/FullArch/"Mercury"/SubDirName
> +        DirComponents = ["Mercury", Grade, FullArch, "Mercury", SubDirName]
>      ;
> -        DirName = "Mercury"/SubDirName
> +        DirComponents = ["Mercury", SubDirName]
>      ),
>      (
>          MkDir = yes,
> +        DirName = dir.relative_path_name_from_components(DirComponents),
>          make_directory(DirName, _, !IO)
>      ;
>          MkDir = no
>      ),
> -    FileName = DirName/BaseName.
> +    Components = DirComponents ++ [BaseName],
> +    FileName = dir.relative_path_name_from_components(Components).
>  
>  :- pred file_is_arch_or_grade_dependent(globals::in, string::in) is semidet.
>  
> Index: library/dir.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/library/dir.m,v
> retrieving revision 1.45
> diff -u -r1.45 dir.m
> --- library/dir.m	23 Nov 2007 07:35:55 -0000	1.45
> +++ library/dir.m	27 Feb 2008 05:21:17 -0000
> @@ -162,6 +162,13 @@
>  :- func string / string = string.
>  :- func dir.make_path_name(string, string) = string.
>  
> +    % relative_path_name_from_components(List) = PathName.
> +    %
> +    % Return the relative pathname from the components in the list.  The
> +    % components of the list are assumed not to contain directory separators.
> +    %
> +:- func dir.relative_path_name_from_components(list(string)) = string.
> +
>  %-----------------------------------------------------------------------------%
>  
>      % io.current_directory(Result)
> @@ -825,6 +832,10 @@
>              FileName])
>      ).
>  
> +dir.relative_path_name_from_components(Components) = PathName :-
> +    Sep = string.from_char(dir.directory_separator),
> +    PathName = string.join_list(Sep, Components).
> +
>  %-----------------------------------------------------------------------------%
>  
>  :- pragma foreign_proc("C",

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list