Skip to content

Commit 310b6a5

Browse files
committed
optimise core functions
1 parent f918c09 commit 310b6a5

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: nanonext
22
Type: Package
33
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
4-
Version: 0.9.2.9035
4+
Version: 0.9.2.9036
55
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
66
a socket library providing high-performance scalability protocols, a
77
cross-platform standard for messaging and communications. Serves as a

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# nanonext 0.9.2.9035 (development)
1+
# nanonext 0.9.2.9036 (development)
22

33
#### New Features
44

src/core.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,19 @@ static SEXP rawOneString(unsigned char *bytes, R_xlen_t nbytes, R_xlen_t *np) {
8888
char *cbuf;
8989
SEXP res;
9090

91-
for (i = *np, p = bytes + (*np); i < nbytes; p++, i++)
91+
for (i = *np, p = bytes + *np; i < nbytes; p++, i++)
9292
if (*p == '\0') break;
9393

9494
if (i < nbytes) {
95-
p = bytes + (*np);
95+
p = bytes + *np;
96+
res = Rf_mkCharLenCE((char *) p, (int) (i - *np), CE_NATIVE);
9697
*np = i + 1;
97-
res = Rf_mkChar((char *) p);
9898
} else {
99-
cbuf = R_chk_calloc(nbytes - (*np) + 1, 1);
100-
memcpy(cbuf, bytes + (*np), nbytes - (*np));
101-
*np = nbytes;
102-
res = Rf_mkChar(cbuf);
99+
cbuf = R_chk_calloc(nbytes - *np + 1, sizeof(char));
100+
memcpy(cbuf, bytes + *np, nbytes - *np);
101+
res = Rf_mkCharLenCE(cbuf, (int) (nbytes - *np), CE_NATIVE);
103102
R_Free(cbuf);
103+
*np = nbytes;
104104
}
105105

106106
return res;

src/tls.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ static SEXP nano_hashToChar(unsigned char *buf, size_t sz) {
6666

6767
SEXP out;
6868
char cbuf[sz + sz + 1];
69-
char *cptr = &cbuf[0];
69+
char *cptr = cbuf;
7070

7171
for (size_t i = 0; i < sz; i++)
7272
cptr += snprintf(cptr, 3, "%.2x", buf[i]);
7373

7474
PROTECT(out = Rf_allocVector(STRSXP, 1));
75-
SET_STRING_ELT(out, 0, Rf_mkCharLenCE(cbuf, sz + sz, CE_NATIVE));
75+
SET_STRING_ELT(out, 0, Rf_mkCharLenCE(cbuf, (int) (sz + sz), CE_NATIVE));
7676

7777
UNPROTECT(1);
7878
return out;

0 commit comments

Comments
 (0)