Skip to content

Commit 4e66795

Browse files
committed
Perl_newSVobject - adjusted for the default values
`newSV_type(SVt_PVOBJ)` does the following initialization: * `ObjectMAXFIELD(sv) = -1;` * `ObjectFIELDS(sv) = NULL;` This commit makes two changes to `Perl_newSVobject` reflecting that: 1. There's no need for `Perl_newSVobject` to set either of these fields if `fieldcount` is zero, so that line is coverted into a DEBUGGING assert()` and one added for `ObjectMAXFIELD(sv)` for completeness. 2. When `fieldcount` is non-zero, setting `ObjectMAXFIELD(sv)` prior to the `Newx()` is more likely to result in the compiler realising that it only needs to do one `ObjectMAXFIELD(sv)` STORE rather than two.
1 parent 86ccb03 commit 4e66795

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

class.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ Perl_newSVobject(pTHX_ Size_t fieldcount)
3838
SV *sv = newSV_type(SVt_PVOBJ);
3939

4040
if (fieldcount) {
41+
ObjectMAXFIELD(sv) = fieldcount - 1;
4142
Newx(ObjectFIELDS(sv), fieldcount, SV *);
4243
Zero(ObjectFIELDS(sv), fieldcount, SV *);
4344
}
45+
#ifdef DEBUGGING
4446
else {
45-
ObjectFIELDS(sv) = NULL;
47+
assert(!ObjectFIELDS(sv));
48+
assert(ObjectMAXFIELD(sv) == -1);
4649
}
47-
ObjectMAXFIELD(sv) = fieldcount - 1;
48-
50+
#endif
4951
return sv;
5052
}
5153

0 commit comments

Comments
 (0)