Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clean-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
clean-and-itasks
clean-platform
Commits
7ba2a7c6
Verified
Commit
7ba2a7c6
authored
Mar 29, 2020
by
Camil Staps
🚀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce heap usage of System.FilePath; add concatPaths to avoid many </> concatenations
parent
916cbcb8
Pipeline
#40687
passed with stage
in 1 minute and 53 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
11 deletions
+44
-11
src/libraries/OS-Independent/System/FilePath.dcl
src/libraries/OS-Independent/System/FilePath.dcl
+9
-0
src/libraries/OS-Independent/System/FilePath.icl
src/libraries/OS-Independent/System/FilePath.icl
+35
-11
No files found.
src/libraries/OS-Independent/System/FilePath.dcl
View file @
7ba2a7c6
...
...
@@ -49,6 +49,9 @@ from System.OSError import :: OSError, :: OSErrorCode, :: OSErrorMessage, :: May
*/
pathSeparator
::
Char
//* `pathSeparator` as a String.
pathSeparatorString
::
String
/**
* Returns a list of all allowed platform path separators
*/
...
...
@@ -59,11 +62,17 @@ pathSeparators :: [Char]
*/
extSeparator
::
Char
//* `extSeparator` as a String.
extSeparatorString
::
String
/**
* Concatenates two paths
*/
(</>)
infixr
5
::
!
FilePath
!
FilePath
->
FilePath
//* Concatenate a list of paths.
concatPaths
::
![
FilePath
]
->
FilePath
/**
* Split a FilePath into filename and extension. The result does not include the extension separator (.).
*
...
...
src/libraries/OS-Independent/System/FilePath.icl
View file @
7ba2a7c6
...
...
@@ -14,14 +14,32 @@ import qualified System._FilePath
pathSeparator
::
Char
pathSeparator
=
OS_PATH_SEPARATOR
pathSeparatorString
::
String
pathSeparatorString
=:
{#
pathSeparator
}
pathSeparators
::
[
Char
]
pathSeparators
=
[
'
\\
'
,
'
/'
]
extSeparator
::
Char
extSeparator
=
'.'
extSeparatorString
::
String
extSeparatorString
=:
{#
extSeparator
}
(</>)
infixr
5
::
!
FilePath
!
FilePath
->
FilePath
(</>)
x
y
=
(
addTrailingPathSeparator
x
)
+++
y
(</>)
x
y
|
hasTrailingPathSeparator
x
=
x
+++
y
=
concat
[
x
,
pathSeparatorString
,
y
]
concatPaths
::
![
FilePath
]
->
FilePath
concatPaths
paths
=
concat
(
addSeparators
paths
)
where
addSeparators
[]
=
[]
addSeparators
[
p
:
ps
]
|
hasTrailingPathSeparator
p
=
[
p
:
addSeparators
ps
]
=
[
p
,
pathSeparatorString
:
ps
]
splitExtension
::
!
FilePath
->
(
String
,
String
)
splitExtension
path
=
split
sz
...
...
@@ -46,23 +64,29 @@ dropExtension :: !FilePath -> String
dropExtension
path
=
fst
(
splitExtension
path
)
addExtension
::
!
FilePath
!
String
->
FilePath
addExtension
path
""
=
path
addExtension
path
ext
|
path
.[
size
path
-
1
]
==
extSeparator
=
path
+++
ext
addExtension
path
ext
=
path
+++
{
extSeparator
}
+++
ext
addExtension
path
ext
|
size
ext
==
0
=
path
#
sz
=
size
path
|
sz
==
0
=
ext
|
path
.[
sz
-1
]
==
extSeparator
=
path
+++
ext
=
concat
[
path
,
extSeparatorString
,
ext
]
replaceExtension
::
!
FilePath
!
String
->
FilePath
replaceExtension
path
ext
=
addExtension
(
dropExtension
path
)
ext
hasTrailingPathSeparator
::
!
FilePath
->
Bool
hasTrailingPathSeparator
""
=
False
hasTrailingPathSeparator
path
=
path
.[
size
path
-
1
]
==
pathSeparator
addTrailingPathSeparator
::
!
FilePath
->
FilePath
addTrailingPathSeparator
path
=
if
(
hasTrailingPathSeparator
path
)
path
(
path
+++
{
pathSeparator
})
hasTrailingPathSeparator
path
#
sz
=
size
path
|
sz
==
0
=
False
=
path
.[
sz
-1
]
==
pathSeparator
splitFileName
::
!
FilePath
->
(
String
,
String
)
splitFileName
path
=
case
lastIndexOf
{
pathSeparator
}
path
of
case
lastIndexOf
pathSeparatorString
path
of
-1
->
(
""
,
path
)
i
->
(
subString
0
i
path
,
subString
(
i
+1
)
(
size
path
-
i
-
1
)
path
)
...
...
@@ -70,7 +94,7 @@ takeDirectory :: !FilePath -> FilePath
takeDirectory
path
=
fst
(
splitFileName
path
)
dropDirectory
::
!
FilePath
->
String
dropDirectory
path
=
case
lastIndexOf
{
pathSeparator
}
path
of
dropDirectory
path
=
case
lastIndexOf
pathSeparatorString
path
of
-1
=
path
i
|
i
==
sizePath
-
1
=
dropDirectory
$
subString
0
(
sizePath
-
1
)
path
// drop file separator at end of path
|
otherwise
=
subString
(
i
+1
)
(
sizePath
-
i
-
1
)
path
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment