Skip to content

Commit f605644

Browse files
committed
optimise one more
1 parent 310b6a5 commit f605644

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
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.9036
4+
Version: 0.9.2.9037
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.9036 (development)
1+
# nanonext 0.9.2.9037 (development)
22

33
#### New Features
44

src/core.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,10 @@ SEXP nano_decode(unsigned char *buf, size_t sz, const int mod) {
356356

357357
switch (mod) {
358358
case 2:
359-
PROTECT(data = Rf_allocVector(STRSXP, sz));
359+
size = sz / 2 + 1;
360+
PROTECT(data = Rf_allocVector(STRSXP, size));
360361
R_xlen_t i, m, nbytes = sz, np = 0;
361-
for (i = 0, m = 0; i < sz; i++) {
362+
for (i = 0, m = 0; i < size; i++) {
362363
SEXP onechar = rawOneString(buf, nbytes, &np);
363364
if (onechar == R_NilValue) break;
364365
SET_STRING_ELT(data, i, onechar);

tests/tests.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ nanotestn(stop_aio(n))
100100
nanotest(identical(call_aio(msg), msg))
101101
nanotesterr(msg$data, "active")
102102
nanotest(identical(call_aio(n), n))
103-
nanotest(!is_aio(n))
104103
nanotestaio(sraio <- n$send_aio(as.raw(0L), mode = "r", timeout = 500))
105104
nanotestaio(rraio <- n1$recv_aio(mode = 1L, timeout = 500))
106105
nanotestw(is_nul_byte(call_aio(rraio)$data))
107-
nanotestaio(sraio <- n$send_aio(c(1+2i, 4+3i), mode = "ra", timeout = 500))
106+
nanotestaio(sraio <- n$send_aio(as.raw(1L), mode = "ra", timeout = 500))
107+
nanotestaio(rraio <- n1$recv_aio(mode = "raw", timeout = 500))
108+
nanotest(is.raw(call_aio(rraio)$data))
109+
nanotestaio(sraio <- n$send_aio(c(1+2i, 4+3i), mode = "raw", timeout = 500))
108110
nanotestaio(rraio <- n1$recv_aio(mode = "co", timeout = 500))
109111
nanotest(is.complex(call_aio(rraio)$data))
110112
nanotestaio(sraio <- n$send_aio(5, mode = "raw", timeout = 500))
@@ -203,11 +205,15 @@ nanotest(!unresolved(msg))
203205
nanotest(is.integer(req$send(c(TRUE, FALSE, TRUE), mode = 2L, block = 500)))
204206
nanotestaio(msg <- recv_aio(ctx, mode = 6L, timeout = 500))
205207
nanotest(is.logical(call_aio(msg)$data))
206-
nanotestaio(err <- send_aio(ctx, msg, mode = 2L))
208+
nanotestaio(err <- send_aio(ctx, msg, mode = "raw"))
207209
nanotestn(stop_aio(err))
208210
nanotesterr(err$result, "active")
209211
nanotestaio(err <- send_aio(ctx, "test"))
210212
nanotest(is_error_value(call_aio(err)$result))
213+
nanotest(is.integer(req$send(as.raw(1L), mode = 2L, block = 500)))
214+
nanotestaio(msg <- call_aio(recv_aio(ctx, mode = 8L, timeout = 500)))
215+
nanotestaio(envraw <- send_aio(ctx, msg, mode = 2L, timeout = 500))
216+
nanotest(identical(req$recv(mode = 8L, block = 500), as.raw(1L)))
211217
nanotestaio(rek <- request(req$context, c(1+3i, 4+2i), recv_mode = "complex", timeout = 500))
212218
nanotest(is.integer(reply(ctx, execute = identity, send_mode = "ra", timeout = 500)))
213219
nanotest(is.complex(call_aio(rek)[["data"]]))

0 commit comments

Comments
 (0)