Skip to main content

Module cached_class

Module cached_class 

Source
Expand description

Cached R class attribute SEXPs.

Frequently-used class vectors (like c("POSIXct", "POSIXt")) and attribute values are allocated once and preserved permanently. This avoids repeated Rf_mkCharLenCE hash lookups on hot paths.

Two declarative macros handle the boilerplate:

โ“˜
// Cache a symbol (Rf_install result):
cached_symbol!(pub(crate) fn tzone_symbol() = c"tzone");

// Cache a STRSXP vector (class, names, etc.):
cached_strsxp!(pub(crate) fn posixct_class_sexp() = [c"POSIXct", c"POSIXt"]);
cached_strsxp!(pub(crate) fn date_class_sexp() = [c"Date"]);

Both expand to a function with a static OnceLock<SEXP> inside. First call initializes; subsequent calls are a single atomic load.

CHARSXPs are obtained via Rf_install + PRINTNAME โ€” symbols are never collected, so the CHARSXP is permanently valid. STRSXP vectors are kept alive via R_PreserveObject.

Macrosยง

cached_strsxp ๐Ÿ”’
Cache a STRSXP vector built from permanent CHARSXPs.
cached_symbol ๐Ÿ”’
Cache an Rf_install symbol result.

Functionsยง

data_frame_class_sexp ๐Ÿ”’
Cached "data.frame" class STRSXP.
error_names_sexp ๐Ÿ”’
Cached c("error", "kind", "call") names STRSXP for error values.
rust_error_attr_symbol ๐Ÿ”’
Cached __rust_error__ symbol.
rust_error_class_sexp ๐Ÿ”’
Cached "rust_error_value" class STRSXP.