www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14865] New: Elide calling invariant for classes with no


          Issue ID: 14865
           Summary: Elide calling invariant for classes with no invariant
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dmitry.olsh gmail.com

See relevant discussion:
http://forum.dlang.org/thread/xdcfidwawitalwjgqzfr forum.dlang.org?page=1

It's a common knowledge that class invariant stays injected as a call to some
internal routine even if there is no user-defined invariant for a given class.
It should be elided or at the very least inlined and carried on to all of the
usual optimizations to avoid redundant null checks (it seems to check for null
pointer only by default). 

Citing the relevant part of discussion:

On 8/3/15 12:59 PM, Dmitry Olshansky wrote:
 On 03-Aug-2015 19:54, Steven Schveighoffer wrote:
 ALSO, make SURE you are compiling in release mode, so you aren't calling
 a virtual invariant function before/after every call.
This one is critical. Actually why do we have an extra call for trivial null-check on any object that doesn't even have invariant?
Actually, that the call to the invariant should be avoidable if the object doesn't have one. It should be easy to check the vtable pointer to see if it points at the "default" invariant (which does nothing). -Steve --
Aug 03 2015