Skip to content

Commit 44f26b9

Browse files
committed
Use smallest local variable scope in GetVpValueWithPrec
1 parent f828d72 commit 44f26b9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

ext/bigdecimal/bigdecimal.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,7 @@ static VALUE rb_rational_convert_to_BigDecimal(VALUE val, size_t digs, int raise
205205
static Real*
206206
GetVpValueWithPrec(VALUE v, long prec, int must)
207207
{
208-
ENTER(1);
209208
Real *pv;
210-
VALUE bg;
211-
char szD[128];
212209

213210
switch(TYPE(v)) {
214211
case T_FLOAT: {
@@ -233,9 +230,11 @@ GetVpValueWithPrec(VALUE v, long prec, int must)
233230
}
234231
break;
235232

236-
case T_FIXNUM:
233+
case T_FIXNUM: {
234+
char szD[128];
237235
sprintf(szD, "%ld", FIX2LONG(v));
238236
return VpCreateRbObject(VpBaseFig() * 2 + 1, szD, true);
237+
}
239238

240239
#ifdef ENABLE_NUMERIC_STRING
241240
case T_STRING:
@@ -244,11 +243,14 @@ GetVpValueWithPrec(VALUE v, long prec, int must)
244243
RSTRING_PTR(v), true);
245244
#endif /* ENABLE_NUMERIC_STRING */
246245

247-
case T_BIGNUM:
248-
bg = rb_big2str(v, 10);
249-
PUSH(bg);
250-
return VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1,
251-
RSTRING_PTR(bg), true);
246+
case T_BIGNUM: {
247+
VALUE bg = rb_big2str(v, 10);
248+
pv = VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1,
249+
RSTRING_PTR(bg), true);
250+
RB_GC_GUARD(bg);
251+
return pv;
252+
}
253+
252254
default:
253255
goto SomeOneMayDoIt;
254256
}

0 commit comments

Comments
 (0)