Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
e284a95c
Commit
e284a95c
authored
Jul 04, 2015
by
Paul Sokolovsky
Browse files
ubinascii: b2a_base64: Optimize away a modulo operation.
parent
616986a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
extmod/modubinascii.c
View file @
e284a95c
...
...
@@ -147,17 +147,20 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
vstr_t
vstr
;
vstr_init_len
(
&
vstr
,
((
bufinfo
.
len
!=
0
)
?
(((
bufinfo
.
len
-
1
)
/
3
)
+
1
)
*
4
:
0
)
+
1
);
// First pass, we convert input buffer to numeric base 64 values
byte
*
in
=
bufinfo
.
buf
,
*
out
=
(
byte
*
)
vstr
.
buf
;
for
(
mp_uint_t
i
=
bufinfo
.
len
;
i
>=
3
;
i
-=
3
)
{
mp_uint_t
i
;
for
(
i
=
bufinfo
.
len
;
i
>=
3
;
i
-=
3
)
{
*
out
++
=
(
in
[
0
]
&
0xFC
)
>>
2
;
*
out
++
=
(
in
[
0
]
&
0x03
)
<<
4
|
(
in
[
1
]
&
0xF0
)
>>
4
;
*
out
++
=
(
in
[
1
]
&
0x0F
)
<<
2
|
(
in
[
2
]
&
0xC0
)
>>
6
;
*
out
++
=
in
[
2
]
&
0x3F
;
in
+=
3
;
}
if
(
bufinfo
.
len
%
3
!=
0
)
{
if
(
i
!=
0
)
{
*
out
++
=
(
in
[
0
]
&
0xFC
)
>>
2
;
if
(
bufinfo
.
len
%
3
==
2
)
{
if
(
i
==
2
)
{
*
out
++
=
(
in
[
0
]
&
0x03
)
<<
4
|
(
in
[
1
]
&
0xF0
)
>>
4
;
*
out
++
=
(
in
[
1
]
&
0x0F
)
<<
2
;
}
...
...
@@ -167,6 +170,8 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
}
*
out
++
=
64
;
}
// Second pass, we convert number base 64 values to actual base64 ascii encoding
out
=
(
byte
*
)
vstr
.
buf
;
for
(
mp_uint_t
i
=
vstr
.
len
-
1
;
i
--
;)
{
if
(
*
out
<
26
)
{
...
...
Write
Preview
Supports
Markdown
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