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
15
Issues
15
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
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
28401140
Verified
Commit
28401140
authored
Aug 17, 2019
by
Camil Staps
🚀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
base64(URL)EncodeLen: avoid string concatenation for performance
parent
5a4908b6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
9 deletions
+20
-9
src/libraries/OS-Independent/Text/Encodings/Base64.icl
src/libraries/OS-Independent/Text/Encodings/Base64.icl
+20
-9
No files found.
src/libraries/OS-Independent/Text/Encodings/Base64.icl
View file @
28401140
...
...
@@ -59,15 +59,25 @@ encodeString s a
|
otherwise
=
encodeLastOctet
(
oct
>>
6
)
(
off
-
1
)
p
{
s
&
[
off
+
dest_o
]
=
a
.[
oct
bitand
63
]}
srcSize
=
size
s
addLineBreaks
::
!
.
String
Length
->
.
String
addLineBreaks
::
!
u
:
String
!
Length
->
u
:
String
addLineBreaks
s
l
|
l
>
0
=
addLineBreaks`
s
""
l
|
otherwise
=
abort
"Length cannot be 0 or less."
|
l
<=
0
=
abort
"Length cannot be 0 or less."
#
sz
=
size
s
|
sz
<=
l
=
s
#
required
=
case
sz
rem
l
of
0
->
(
sz
/
l
)
*
(
l
+1
)
-
1
r
->
(
sz
/
l
)
*
(
l
+1
)
+
r
=
copy
s
0
l
(
createArray
required
'\0'
)
0
where
addLineBreaks`
::
!.
String
!.
String
!
Length
->
.
String
addLineBreaks`
src
dest
len
|
len
>=
(
size
src
)
=
dest
+++.
src
|
otherwise
=
addLineBreaks`
(
src
%
(
len
,(
size
src
)))
(
dest
+++(
src
%
(
0
,
len
-1
))+++
"
\n
"
)
len
copy
::
!.
String
!
Int
!
Int
!*
String
!
Int
->
.
String
copy
src
src_o
remaining
dest
dest_o
|
src_o
>=
size
src
=
dest
|
remaining
==
0
=
copy
src
src_o
l
{
dest
&
[
dest_o
]=
'\n'
}
(
dest_o
+1
)
=
copy
src
(
src_o
+1
)
(
remaining
-1
)
{
dest
&
[
dest_o
]=
src
.[
src_o
]}
(
dest_o
+1
)
base64Decode
::
!.
String
->
.
String
base64Decode
s
=
decodeString
s
decodeWithStdAlphabet
...
...
@@ -141,12 +151,13 @@ where
decodeString`
::
!.
String
!
Int
!
Alphabet
!*{#
Char
}
!
Int
!
Int
->
*{#
Char
}
decodeString`
s
sz
a
dest
src_o
dest_o
|
src_o
>=
sz
=
dest
#!
(
c1
,
src_o
,
s
)
=
nextChar
s
src_o
sz
#!
(
c2
,
src_o
,
s
)
=
nextChar
s
src_o
sz
#!
(
c3
,
src_o
,
s
)
=
nextChar
s
src_o
sz
#!
(
c4
,
src_o
,
s
)
=
nextChar
s
src_o
sz
|
c4
==
'\0'
|
c1
==
'\0'
=
dest
=
abort
"invalid base64 input: not a multiple of 4
\n
"
|
c3
==
'='
// lose the last four padding bits
#
oct
=
...
...
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