Skip to content

Commit

Permalink
use R_VECTOR as faster version of VECTOR_ELT
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Jun 19, 2024
1 parent 67c3e8b commit ace3f03
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nanonext
Type: Package
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
Version: 1.1.0.9002
Version: 1.1.0.9003
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
a socket library implementing 'Scalability Protocols', a reliable,
high-performance standard for common communications patterns including
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# nanonext 1.1.0.9002 (development)
# nanonext 1.1.0.9003 (development)

#### New Features

Expand All @@ -9,6 +9,7 @@
* `request()` specifying argument 'cv' other than NULL or a 'conditionVariable' will cause the pipe connection to be dropped when the reply is (asynchronously) completed.
* Removes deprecated functions `strcat()`, `recv_aio_signal()` and `request_signal()`.
* Removes `base64enc()` and `base64dec()` in favour of those in the {secretbase} package.
* `later` is now a 'suggests' dependency (only required if using promises).

# nanonext 1.1.0

Expand Down
10 changes: 5 additions & 5 deletions src/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ SEXP rnng_aio_call(SEXP x) {
case VECSXP: ;
const R_xlen_t xlen = Rf_xlength(x);
for (R_xlen_t i = 0; i < xlen; i++) {
rnng_aio_call(VECTOR_ELT(x, i));
rnng_aio_call(R_VECTOR(x)[i]);
}
break;
}
Expand All @@ -581,7 +581,7 @@ static SEXP rnng_aio_collect_impl(SEXP x, SEXP (*const func)(SEXP)) {
const R_xlen_t xlen = Rf_xlength(x);
PROTECT(out = Rf_allocVector(VECSXP, xlen));
for (R_xlen_t i = 0; i < xlen; i++) {
env = func(VECTOR_ELT(x, i));
env = func(R_VECTOR(x)[i]);
if (TYPEOF(env) != ENVSXP) goto exit;
env = Rf_findVarInFrame(env, nano_ValueSymbol);
if (env == R_UnboundValue) goto exit;
Expand Down Expand Up @@ -624,7 +624,7 @@ SEXP rnng_aio_stop(SEXP x) {
case VECSXP: ;
const R_xlen_t xlen = Rf_xlength(x);
for (R_xlen_t i = 0; i < xlen; i++) {
rnng_aio_stop(VECTOR_ELT(x, i));
rnng_aio_stop(R_VECTOR(x)[i]);
}
break;
}
Expand Down Expand Up @@ -678,7 +678,7 @@ SEXP rnng_unresolved(SEXP x) {
case VECSXP: ;
const R_xlen_t xlen = Rf_xlength(x);
for (R_xlen_t i = 0; i < xlen; i++) {
if (rnng_unresolved_impl(VECTOR_ELT(x, i)))
if (rnng_unresolved_impl(R_VECTOR(x)[i]))
return Rf_ScalarLogical(1);
}
}
Expand Down Expand Up @@ -710,7 +710,7 @@ SEXP rnng_unresolved2(SEXP x) {
int xc = 0;
const R_xlen_t xlen = Rf_xlength(x);
for (R_xlen_t i = 0; i < xlen; i++) {
xc += rnng_unresolved2_impl(VECTOR_ELT(x, i));
xc += rnng_unresolved2_impl(R_VECTOR(x)[i]);
}
return Rf_ScalarInteger(xc);
}
Expand Down
14 changes: 7 additions & 7 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static SEXP nano_inHook(SEXP x, SEXP fun) {
PROTECT(newlist = Rf_allocVector(VECSXP, xlen + 1));
PROTECT(newnames = Rf_allocVector(STRSXP, xlen + 1));
for (R_xlen_t i = 0; i < xlen; i++) {
SET_VECTOR_ELT(newlist, i, VECTOR_ELT(list, i));
SET_VECTOR_ELT(newlist, i, R_VECTOR(list)[i]);
SET_STRING_ELT(newnames, i, STRING_ELT(names, i));
}
SET_VECTOR_ELT(newlist, xlen, x);
Expand All @@ -178,7 +178,7 @@ static SEXP nano_inHook(SEXP x, SEXP fun) {
static SEXP nano_outHook(SEXP x, SEXP fun) {

const long i = atol(CHAR(*(SEXP *) DATAPTR_RO(x))) - 1;
return VECTOR_ELT(fun, i);
return R_VECTOR(fun)[i];

}

Expand Down Expand Up @@ -269,7 +269,7 @@ void nano_serialize_next(nano_buf *buf, const SEXP object) {
buf->cur += sizeof(R_xlen_t);

for (R_xlen_t i = 0; i < llen; i++) {
PROTECT(call = Rf_lcons(func, Rf_cons(VECTOR_ELT(refList, i), R_NilValue)));
PROTECT(call = Rf_lcons(func, Rf_cons(R_VECTOR(refList)[i], R_NilValue)));
PROTECT(out = R_UnwindProtect(eval_safe, call, rl_reset, NULL, NULL));
if (TYPEOF(out) == RAWSXP) {
R_xlen_t xlen = XLENGTH(out);
Expand Down Expand Up @@ -1571,8 +1571,8 @@ SEXP rnng_next_config(SEXP refhook, SEXP klass, SEXP list, SEXP mark) {
case VECSXP:
if (Rf_xlength(refhook) != 2)
return nano_refHook;
typ1 = TYPEOF(VECTOR_ELT(refhook, 0));
typ2 = TYPEOF(VECTOR_ELT(refhook, 1));
typ1 = TYPEOF(R_VECTOR(refhook)[0]);
typ2 = TYPEOF(R_VECTOR(refhook)[1]);
plist = 0;
break;
case NILSXP:
Expand All @@ -1586,8 +1586,8 @@ SEXP rnng_next_config(SEXP refhook, SEXP klass, SEXP list, SEXP mark) {
if ((typ1 == CLOSXP || typ1 == SPECIALSXP || typ1 == BUILTINSXP) &&
(typ2 == CLOSXP || typ2 == SPECIALSXP || typ2 == BUILTINSXP)) {

SETCAR(nano_refHook, plist ? CAR(refhook) : VECTOR_ELT(refhook, 0));
SETCADR(nano_refHook, plist ? CADR(refhook) : VECTOR_ELT(refhook, 1));
SETCAR(nano_refHook, plist ? CAR(refhook) : R_VECTOR(refhook)[0]);
SETCADR(nano_refHook, plist ? CADR(refhook) : R_VECTOR(refhook)[1]);
SETCAR(nano_klassString, STRING_ELT(klass, 0));

registered = *NANO_INTEGER(list) ? 1 : 2;
Expand Down
2 changes: 2 additions & 0 deletions src/nanonext.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ typedef struct nano_cv_s {
#include <Rversion.h>
#include <R_ext/Visibility.h>

#define R_VECTOR(x) ((const SEXP *) DATAPTR_RO(x))

#define ERROR_OUT(xc) Rf_error("%d | %s", xc, nng_strerror(xc))
#define ERROR_RET(xc) { Rf_warning("%d | %s", xc, nng_strerror(xc)); return mk_error(xc); }
#define NANONEXT_INIT_BUFSIZE 8192
Expand Down
2 changes: 1 addition & 1 deletion src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ SEXP rnng_wait_thread_create(SEXP x) {

const R_xlen_t xlen = Rf_xlength(x);
for (R_xlen_t i = 0; i < xlen; i++) {
rnng_wait_thread_create(VECTOR_ELT(x, i));
rnng_wait_thread_create(R_VECTOR(x)[i]);
}

}
Expand Down

0 comments on commit ace3f03

Please sign in to comment.