Skip to content

Commit 7512030

Browse files
abinashmeher999isuruf
authored andcommitted
basic on stack wherever possible in ruby_basic.c
1 parent 2739997 commit 7512030

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

ext/symengine/ruby_basic.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ VALUE cbasic_alloc(VALUE klass){
1616
}
1717

1818
VALUE cbasic_binary_op(VALUE self, VALUE operand2, void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*)){
19-
basic_struct *this, *cbasic_operand2, *cresult;
19+
basic_struct *this, *cresult;
2020
VALUE result;
2121

22-
cbasic_operand2 = basic_new_heap();
22+
basic cbasic_operand2;
23+
basic_new_stack(cbasic_operand2);
2324

2425
Data_Get_Struct(self, basic_struct, this);
2526
sympify(operand2, cbasic_operand2);
2627

2728
cresult = basic_new_heap();
2829
cwfunc_ptr(cresult, this, cbasic_operand2);
2930
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
30-
basic_free_heap(cbasic_operand2);
31+
basic_free_stack(cbasic_operand2);
3132

3233
return result;
3334
}
@@ -89,27 +90,29 @@ VALUE cbasic_diff(VALUE self, VALUE operand2) {
8990
}
9091

9192
VALUE cbasic_eq(VALUE self, VALUE operand2) {
92-
basic_struct *this, *cbasic_operand2;
93+
basic_struct *this;
9394

94-
cbasic_operand2 = basic_new_heap();
95+
basic cbasic_operand2;
96+
basic_new_stack(cbasic_operand2);
9597
Data_Get_Struct(self, basic_struct, this);
9698
sympify(operand2, cbasic_operand2);
9799

98100
VALUE ret_val = basic_eq(this, cbasic_operand2) ? Qtrue : Qfalse;
99-
basic_free_heap(cbasic_operand2);
101+
basic_free_stack(cbasic_operand2);
100102

101103
return ret_val;
102104
}
103105

104106
VALUE cbasic_neq(VALUE self, VALUE operand2) {
105-
basic_struct *this, *cbasic_operand2;
107+
basic_struct *this;
106108

107-
cbasic_operand2 = basic_new_heap();
109+
basic cbasic_operand2;
110+
basic_new_stack(cbasic_operand2);
108111
Data_Get_Struct(self, basic_struct, this);
109112
sympify(operand2, cbasic_operand2);
110113

111114
VALUE ret_val = basic_neq(this, cbasic_operand2) ? Qtrue : Qfalse;
112-
basic_free_heap(cbasic_operand2);
115+
basic_free_stack(cbasic_operand2);
113116

114117
return ret_val;
115118
}

0 commit comments

Comments
 (0)