Skip to content

Commit 477ca17

Browse files
committed
Update benchmark utils.
1 parent 2e6a8f0 commit 477ca17

File tree

4 files changed

+6
-45
lines changed

4 files changed

+6
-45
lines changed

benchmark/benchmark.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ extern int libiconv_static_size_convert(void* cd, const char *input_data, size_t
1313
size_t output_length);
1414

1515
extern void* reiconv_iconv_open();
16-
extern int reiconv_static_size_convert(void* cd, const char *input_data, size_t input_length, char *output_data,
17-
size_t output_length); // Unused.
16+

benchmark/benchmark.png

-48.2 KB
Loading

benchmark/compile.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
g++ *.cpp /tmp/inst/lib/libcppp-reiconv.static.a /tmp/inst/lib/libcharset.a /tmp/inst/lib/libiconv.a -I/tmp/inst/include /workspaces/benchmark/build/src/libbenchmark.a -licuuc -O3 -fPIC -o benchmark

benchmark/reiconv_iconv.cpp

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,13 @@
11
#include "benchmark.hpp"
22

3+
#include <cppp/reiconv.h>
4+
35
#include <cerrno>
46
#include <cstdlib>
57
#include <cstring>
68

7-
#define iconv_t reiconv_t
8-
#define iconv_open reiconv_open
9-
#define iconv reiconv_iconv
10-
#define iconv_close reiconv_handle_close
11-
12-
extern "C"
13-
{
14-
typedef void *iconv_t;
15-
extern int iconv_close(iconv_t cd);
16-
extern iconv_t iconv_open(const char *tocode, const char *fromcode);
17-
extern size_t iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
18-
}
19-
209
void* reiconv_iconv_open()
2110
{
22-
return iconv_open("GB18030", "UTF-8");
11+
return reiconv_open_from_index(ENCODING_UTF8, ENCODING_GB18030, REICONV_NO_FLAGS);
2312
}
2413

25-
int reiconv_static_size_convert(void* cd, const char *input_data, size_t input_length, char *output_data,
26-
size_t output_length)
27-
{
28-
char *inptr = (char *)input_data;
29-
size_t insize = input_length;
30-
char *outptr = output_data;
31-
size_t outsize = output_length;
32-
while (insize > 0)
33-
{
34-
size_t res = iconv(cd, &inptr, &insize, &outptr, &outsize);
35-
if (res == (size_t)(-1))
36-
{
37-
if (errno == EINVAL)
38-
{
39-
break;
40-
}
41-
else
42-
{
43-
return -1;
44-
}
45-
}
46-
}
47-
if (iconv(cd, NULL, NULL, &outptr, &outsize) == (size_t)(-1))
48-
{
49-
return -1;
50-
}
51-
memset(outptr, 0, outsize); // Fill the rest of the buffer with '\0'.
52-
return 0;
53-
}

0 commit comments

Comments
 (0)