Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-blobcode
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-blobcode
Commits
edca76e2
Commit
edca76e2
authored
Jan 12, 2016
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some optimization for hex_decode()
parent
09f3a681
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
18 deletions
+22
-18
hex.c
src/hex.c
+22
-16
vmod_convert.c
src/vmod_convert.c
+0
-1
vmod_convert.h
src/vmod_convert.h
+0
-1
No files found.
src/hex.c
View file @
edca76e2
...
...
@@ -28,6 +28,7 @@
#include <ctype.h>
#include <errno.h>
#include <stdint.h>
#include "vmod_convert.h"
...
...
@@ -39,7 +40,19 @@ static const char hex_alphabet[][16] = {
"0123456789ABCDEF"
};
static
char
nibble
[
128
];
/*
* Shift the ASCII table over so that it begins at '0', and replace the
* hex digits with their binary values. This fits all of the hex digits
* into 54 bytes (cacheline friendly).
*/
static
const
uint8_t
nibble
[]
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
10
,
11
,
12
,
13
,
14
,
15
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
10
,
11
,
12
,
13
,
14
,
15
};
static
inline
int
isxstr
(
const
char
*
const
p
,
ssize_t
*
l
)
...
...
@@ -75,6 +88,12 @@ check(const char * const p, va_list ap)
return
len
;
}
static
inline
char
hex2byte
(
const
unsigned
char
hi
,
const
unsigned
char
lo
)
{
return
(
nibble
[
hi
-
'0'
]
<<
4
)
|
nibble
[
lo
-
'0'
];
}
static
inline
void
decode_str
(
const
char
*
restrict
const
p
,
char
*
restrict
*
restrict
dest
,
unsigned
char
*
restrict
extranib
)
...
...
@@ -83,28 +102,15 @@ decode_str(const char *restrict const p, char *restrict *restrict dest,
char
*
d
=
*
dest
;
if
(
*
extranib
)
*
d
++
=
(
nibble
[
*
extranib
]
<<
4
)
|
nibble
[
*
s
++
]
;
*
d
++
=
hex2byte
(
*
extranib
,
*
s
++
)
;
while
(
*
s
&&
*
(
s
+
1
))
{
*
d
++
=
(
nibble
[
*
s
]
<<
4
)
|
nibble
[
*
(
s
+
1
)]
;
*
d
++
=
hex2byte
(
*
s
,
*
(
s
+
1
))
;
s
+=
2
;
}
*
extranib
=
*
s
;
*
dest
+=
d
-
*
dest
;
}
void
hex_init
(
void
)
{
for
(
int
i
=
0
;
i
<
128
;
i
++
)
nibble
[
i
]
=
-
1
;
for
(
char
c
=
'0'
;
c
<=
'9'
;
c
++
)
nibble
[(
int
)
c
]
=
c
-
'0'
;
for
(
char
c
=
'a'
;
c
<=
'f'
;
c
++
)
nibble
[(
int
)
c
]
=
c
-
'a'
+
10
;
for
(
char
c
=
'A'
;
c
<=
'F'
;
c
++
)
nibble
[(
int
)
c
]
=
c
-
'A'
+
10
;
}
ssize_t
hex_encode
(
const
enum
encoding
enc
,
char
*
restrict
const
buf
,
const
size_t
maxlen
,
const
char
*
restrict
const
in
,
...
...
src/vmod_convert.c
View file @
edca76e2
...
...
@@ -151,7 +151,6 @@ event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e event)
if
(
event
!=
VCL_EVENT_LOAD
)
return
0
;
hex_init
();
base64_init
();
return
(
0
);
}
...
...
src/vmod_convert.h
View file @
edca76e2
...
...
@@ -109,6 +109,5 @@ void base64_init(void);
encode_f
base64_encode
;
/* hex.c */
void
hex_init
(
void
);
encode_f
hex_encode
;
decode_f
hex_decode
;
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