New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace the createNull
method with a public static const s_null
data member
#233
Comments
createNull
method with a static s_null
data member createNull
method with a public static const s_null
data member
Hi Brock! Would this open up any order-of-initialization issues for statics? We might want the s_null field to be a static local in a static function, initialized in a BCEMT_ONCE_DO just to avoid that possibility. This sounds like a good idea, but I think we should wait for @mversche or Atilla to comment since they know more about Datum than I do. Thanks, Mike |
Hi Mike! That's a quick response! I don't think it would cause any ordering problems -- Datum result;
#ifdef BSLS_PLATFORM_CPU_32_BIT
// Setting exponent using half-word is faster, maybe the compiler folds the
// two statements into one?
result.d_as.d_exponent = k_DOUBLE_MASK | Datum::e_INTERNAL_EXTENDED;
result.d_as.d_ushort = e_EXTENDED_INTERNAL_NIL;
#else // BSLS_PLATFORM_CPU_32_BIT
result.d_as.d_type = e_INTERNAL_NIL;
#endif // BSLS_PLATFORM_CPU_32_BIT
return result; But yes, definitely happy to hear the opinions of @mversche and Attila. |
Why would a static data member be more efficient? I would imagine you should just make |
@dharesign, not all of our compilers support constexpr yet. If they did, things would be much simpler, I agree. (also, nice to see another member of the large godbolt.org fan club :) ) |
Yeah, godbolt.org is awesome. The Re. |
I'm not sure just making See below for the various options. In each case, compiling with
Based on this, I'm not sure creating a static A liberal sprinkling of |
"A liberal sprinkling of constexpr where it makes sense looks like it would provide real benefits though." Yeah, I think that is more generally useful than making a static |
Also note that I forgot to define |
I still like the |
Let me summarize my ramblings: there is no benefit from Adding |
There are plenty of situations where a |
I guess I misunderstood your use case, given:
If you have a need for lots of |
That's a good point, and part of the reason I was interested in |
If you actually want to create a And given that there would be no difference, from a performance standpoint, between an |
Frequently, you don't need to create a new object at all. In that case, the static version is far more efficient (this is true if you use |
Closing stale issues |
This change has been discussed with the bde team, and I had intended to make it before handing
Datum
off to them, but never got around to it. It would simplify use ofDatum
, provide a potential performance benefit (as null objects are created frequently), and as a side-benefit, allow the logic in the body ofcreateNull
to move intobdld_datum.cpp
.Note that
createNull
could be left intact (perhaps returning aconst Datum&
) for compatibility.I'll be happy to write the patch myself if this change is approved.
The text was updated successfully, but these errors were encountered: