mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00

The benchmark results show that this feature has either a positive or no impact on performance. The memory usage is also mostly unchanged, except in hexapdf, where there is a decrease in RSS. -------------- ----------- ---------- --------- ----------- ---------- --------- -------------- ------------- bench master (ms) stddev (%) RSS (MiB) branch (ms) stddev (%) RSS (MiB) branch 1st itr master/branch activerecord 70.8 2.2 56.0 71.7 2.2 56.0 0.99 0.99 erubi_rails 20.5 13.6 94.7 20.5 14.3 94.2 0.93 1.00 hexapdf 2541.0 0.7 212.8 2544.4 0.7 203.4 1.00 1.00 liquid-c 65.6 0.3 38.9 65.3 0.3 38.9 1.01 1.01 liquid-compile 63.7 0.3 34.6 61.1 0.2 34.6 1.04 1.04 liquid-render 163.1 0.1 37.1 163.3 0.1 37.1 1.00 1.00 mail 139.3 0.1 50.5 137.0 0.1 50.1 0.99 1.02 psych-load 2065.7 0.1 36.9 2068.2 0.1 37.3 1.00 1.00 railsbench 2034.6 0.5 103.9 2031.9 0.5 103.8 1.02 1.00 ruby-lsp 65.3 3.1 89.8 66.2 3.0 89.7 1.01 0.99 sequel 73.2 1.0 40.3 73.4 1.0 40.3 1.00 1.00 -------------- ----------- ---------- --------- ----------- ---------- --------- -------------- -------------
157 lines
3.8 KiB
C
157 lines
3.8 KiB
C
#ifndef INTERNAL_STRUCT_H /*-*-C-*-vi:se ft=c:*/
|
|
#define INTERNAL_STRUCT_H
|
|
/**
|
|
* @author Ruby developers <ruby-core@ruby-lang.org>
|
|
* @copyright This file is a part of the programming language Ruby.
|
|
* Permission is hereby granted, to either redistribute and/or
|
|
* modify this file, provided that the conditions mentioned in the
|
|
* file COPYING are met. Consult the file for details.
|
|
* @brief Internal header for Struct.
|
|
*/
|
|
#include "ruby/internal/stdbool.h" /* for bool */
|
|
#include "ruby/ruby.h" /* for struct RBasic */
|
|
|
|
enum {
|
|
RSTRUCT_EMBED_LEN_MASK = RUBY_FL_USER7 | RUBY_FL_USER6 | RUBY_FL_USER5 | RUBY_FL_USER4 |
|
|
RUBY_FL_USER3 | RUBY_FL_USER2 | RUBY_FL_USER1,
|
|
RSTRUCT_EMBED_LEN_SHIFT = (RUBY_FL_USHIFT+1),
|
|
RSTRUCT_TRANSIENT_FLAG = RUBY_FL_USER8,
|
|
};
|
|
|
|
struct RStruct {
|
|
struct RBasic basic;
|
|
union {
|
|
struct {
|
|
long len;
|
|
const VALUE *ptr;
|
|
} heap;
|
|
/* This is a length 1 array because:
|
|
* 1. GCC has a bug that does not optimize C flexible array members
|
|
* (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102452)
|
|
* 2. Zero length arrays are not supported by all compilers
|
|
*/
|
|
const VALUE ary[1];
|
|
} as;
|
|
};
|
|
|
|
#define RSTRUCT(obj) ((struct RStruct *)(obj))
|
|
|
|
#ifdef RSTRUCT_LEN
|
|
# undef RSTRUCT_LEN
|
|
#endif
|
|
|
|
#ifdef RSTRUCT_PTR
|
|
# undef RSTRUCT_PTR
|
|
#endif
|
|
|
|
#ifdef RSTRUCT_SET
|
|
# undef RSTRUCT_SET
|
|
#endif
|
|
|
|
#ifdef RSTRUCT_GET
|
|
# undef RSTRUCT_GET
|
|
#endif
|
|
|
|
#define RSTRUCT_LEN internal_RSTRUCT_LEN
|
|
#define RSTRUCT_SET internal_RSTRUCT_SET
|
|
#define RSTRUCT_GET internal_RSTRUCT_GET
|
|
|
|
/* struct.c */
|
|
VALUE rb_struct_init_copy(VALUE copy, VALUE s);
|
|
VALUE rb_struct_lookup(VALUE s, VALUE idx);
|
|
VALUE rb_struct_s_keyword_init(VALUE klass);
|
|
static inline const VALUE *rb_struct_const_heap_ptr(VALUE st);
|
|
static inline bool RSTRUCT_TRANSIENT_P(VALUE st);
|
|
static inline void RSTRUCT_TRANSIENT_SET(VALUE st);
|
|
static inline void RSTRUCT_TRANSIENT_UNSET(VALUE st);
|
|
static inline long RSTRUCT_EMBED_LEN(VALUE st);
|
|
static inline long RSTRUCT_LEN(VALUE st);
|
|
static inline int RSTRUCT_LENINT(VALUE st);
|
|
static inline const VALUE *RSTRUCT_CONST_PTR(VALUE st);
|
|
static inline void RSTRUCT_SET(VALUE st, long k, VALUE v);
|
|
static inline VALUE RSTRUCT_GET(VALUE st, long k);
|
|
|
|
static inline bool
|
|
RSTRUCT_TRANSIENT_P(VALUE st)
|
|
{
|
|
#if USE_TRANSIENT_HEAP
|
|
return FL_TEST_RAW(st, RSTRUCT_TRANSIENT_FLAG);
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
static inline void
|
|
RSTRUCT_TRANSIENT_SET(VALUE st)
|
|
{
|
|
#if USE_TRANSIENT_HEAP
|
|
FL_SET_RAW(st, RSTRUCT_TRANSIENT_FLAG);
|
|
#endif
|
|
}
|
|
|
|
static inline void
|
|
RSTRUCT_TRANSIENT_UNSET(VALUE st)
|
|
{
|
|
#if USE_TRANSIENT_HEAP
|
|
FL_UNSET_RAW(st, RSTRUCT_TRANSIENT_FLAG);
|
|
#endif
|
|
}
|
|
|
|
static inline long
|
|
RSTRUCT_EMBED_LEN(VALUE st)
|
|
{
|
|
long ret = FL_TEST_RAW(st, RSTRUCT_EMBED_LEN_MASK);
|
|
ret >>= RSTRUCT_EMBED_LEN_SHIFT;
|
|
return ret;
|
|
}
|
|
|
|
static inline long
|
|
RSTRUCT_LEN(VALUE st)
|
|
{
|
|
if (FL_TEST_RAW(st, RSTRUCT_EMBED_LEN_MASK)) {
|
|
return RSTRUCT_EMBED_LEN(st);
|
|
}
|
|
else {
|
|
return RSTRUCT(st)->as.heap.len;
|
|
}
|
|
}
|
|
|
|
static inline int
|
|
RSTRUCT_LENINT(VALUE st)
|
|
{
|
|
return rb_long2int(RSTRUCT_LEN(st));
|
|
}
|
|
|
|
static inline const VALUE *
|
|
RSTRUCT_CONST_PTR(VALUE st)
|
|
{
|
|
const struct RStruct *p = RSTRUCT(st);
|
|
|
|
if (FL_TEST_RAW(st, RSTRUCT_EMBED_LEN_MASK)) {
|
|
return p->as.ary;
|
|
}
|
|
else {
|
|
return p->as.heap.ptr;
|
|
}
|
|
}
|
|
|
|
static inline void
|
|
RSTRUCT_SET(VALUE st, long k, VALUE v)
|
|
{
|
|
RB_OBJ_WRITE(st, &RSTRUCT_CONST_PTR(st)[k], v);
|
|
}
|
|
|
|
static inline VALUE
|
|
RSTRUCT_GET(VALUE st, long k)
|
|
{
|
|
return RSTRUCT_CONST_PTR(st)[k];
|
|
}
|
|
|
|
static inline const VALUE *
|
|
rb_struct_const_heap_ptr(VALUE st)
|
|
{
|
|
assert(!FL_TEST_RAW(st, RSTRUCT_EMBED_LEN_MASK));
|
|
return RSTRUCT(st)->as.heap.ptr;
|
|
}
|
|
|
|
#endif /* INTERNAL_STRUCT_H */
|