@@ -3748,6 +3748,55 @@ enumerator_s_product(int argc, VALUE *argv, VALUE klass)
3748
3748
return obj ;
3749
3749
}
3750
3750
3751
+ struct arith_seq {
3752
+ struct enumerator enumerator ;
3753
+ VALUE begin ;
3754
+ VALUE end ;
3755
+ VALUE step ;
3756
+ bool exclude_end ;
3757
+ };
3758
+
3759
+ RUBY_REFERENCES (arith_seq_refs ) = {
3760
+ RUBY_REF_EDGE (struct enumerator , obj ),
3761
+ RUBY_REF_EDGE (struct enumerator , args ),
3762
+ RUBY_REF_EDGE (struct enumerator , fib ),
3763
+ RUBY_REF_EDGE (struct enumerator , dst ),
3764
+ RUBY_REF_EDGE (struct enumerator , lookahead ),
3765
+ RUBY_REF_EDGE (struct enumerator , feedvalue ),
3766
+ RUBY_REF_EDGE (struct enumerator , stop_exc ),
3767
+ RUBY_REF_EDGE (struct enumerator , size ),
3768
+ RUBY_REF_EDGE (struct enumerator , procs ),
3769
+
3770
+ RUBY_REF_EDGE (struct arith_seq , begin ),
3771
+ RUBY_REF_EDGE (struct arith_seq , end ),
3772
+ RUBY_REF_EDGE (struct arith_seq , step ),
3773
+ RUBY_REF_END
3774
+ };
3775
+
3776
+ static const rb_data_type_t arith_seq_data_type = {
3777
+ "arithmetic_sequence" ,
3778
+ {
3779
+ RUBY_REFS_LIST_PTR (arith_seq_refs ),
3780
+ RUBY_TYPED_DEFAULT_FREE ,
3781
+ NULL , // Nothing allocated externally, so don't need a memsize function
3782
+ NULL ,
3783
+ },
3784
+ .parent = & enumerator_data_type ,
3785
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_DECL_MARKING | RUBY_TYPED_EMBEDDABLE
3786
+ };
3787
+
3788
+ static VALUE
3789
+ arith_seq_allocate (VALUE klass )
3790
+ {
3791
+ struct arith_seq * ptr ;
3792
+ VALUE enum_obj ;
3793
+
3794
+ enum_obj = TypedData_Make_Struct (klass , struct arith_seq , & arith_seq_data_type , ptr );
3795
+ ptr -> enumerator .obj = Qundef ;
3796
+
3797
+ return enum_obj ;
3798
+ }
3799
+
3751
3800
/*
3752
3801
* Document-class: Enumerator::ArithmeticSequence
3753
3802
*
@@ -3765,12 +3814,16 @@ rb_arith_seq_new(VALUE obj, VALUE meth, int argc, VALUE const *argv,
3765
3814
rb_enumerator_size_func * size_fn ,
3766
3815
VALUE beg , VALUE end , VALUE step , int excl )
3767
3816
{
3768
- VALUE aseq = enumerator_init (enumerator_allocate (rb_cArithSeq ),
3817
+ VALUE aseq = enumerator_init (arith_seq_allocate (rb_cArithSeq ),
3769
3818
obj , meth , argc , argv , size_fn , Qnil , rb_keyword_given_p ());
3770
- rb_ivar_set (aseq , id_begin , beg );
3771
- rb_ivar_set (aseq , id_end , end );
3772
- rb_ivar_set (aseq , id_step , step );
3773
- rb_ivar_set (aseq , id_exclude_end , RBOOL (excl ));
3819
+ struct arith_seq * ptr ;
3820
+ TypedData_Get_Struct (aseq , struct arith_seq , & enumerator_data_type , ptr );
3821
+
3822
+ RB_OBJ_WRITE (aseq , & ptr -> begin , beg );
3823
+ RB_OBJ_WRITE (aseq , & ptr -> end , end );
3824
+ RB_OBJ_WRITE (aseq , & ptr -> step , step );
3825
+ ptr -> exclude_end = excl ;
3826
+
3774
3827
return aseq ;
3775
3828
}
3776
3829
@@ -3783,7 +3836,9 @@ rb_arith_seq_new(VALUE obj, VALUE meth, int argc, VALUE const *argv,
3783
3836
static inline VALUE
3784
3837
arith_seq_begin (VALUE self )
3785
3838
{
3786
- return rb_ivar_get (self , id_begin );
3839
+ struct arith_seq * ptr ;
3840
+ TypedData_Get_Struct (self , struct arith_seq , & enumerator_data_type , ptr );
3841
+ return ptr -> begin ;
3787
3842
}
3788
3843
3789
3844
/*
@@ -3794,7 +3849,9 @@ arith_seq_begin(VALUE self)
3794
3849
static inline VALUE
3795
3850
arith_seq_end (VALUE self )
3796
3851
{
3797
- return rb_ivar_get (self , id_end );
3852
+ struct arith_seq * ptr ;
3853
+ TypedData_Get_Struct (self , struct arith_seq , & enumerator_data_type , ptr );
3854
+ return ptr -> end ;
3798
3855
}
3799
3856
3800
3857
/*
@@ -3806,7 +3863,9 @@ arith_seq_end(VALUE self)
3806
3863
static inline VALUE
3807
3864
arith_seq_step (VALUE self )
3808
3865
{
3809
- return rb_ivar_get (self , id_step );
3866
+ struct arith_seq * ptr ;
3867
+ TypedData_Get_Struct (self , struct arith_seq , & enumerator_data_type , ptr );
3868
+ return ptr -> step ;
3810
3869
}
3811
3870
3812
3871
/*
@@ -3817,13 +3876,17 @@ arith_seq_step(VALUE self)
3817
3876
static inline VALUE
3818
3877
arith_seq_exclude_end (VALUE self )
3819
3878
{
3820
- return rb_ivar_get (self , id_exclude_end );
3879
+ struct arith_seq * ptr ;
3880
+ TypedData_Get_Struct (self , struct arith_seq , & enumerator_data_type , ptr );
3881
+ return RBOOL (ptr -> exclude_end );
3821
3882
}
3822
3883
3823
3884
static inline int
3824
3885
arith_seq_exclude_end_p (VALUE self )
3825
3886
{
3826
- return RTEST (arith_seq_exclude_end (self ));
3887
+ struct arith_seq * ptr ;
3888
+ TypedData_Get_Struct (self , struct arith_seq , & enumerator_data_type , ptr );
3889
+ return ptr -> exclude_end ;
3827
3890
}
3828
3891
3829
3892
int
0 commit comments