Satisfying inheritence requirements
Bill Baxter
dnewsgroup at billbaxter.com
Wed Oct 10 08:59:58 PDT 2007
Steven Schveighoffer wrote:
> "Jason House" wrote
>> Steven Schveighoffer Wrote:
>>> Now, to give an example where an alias is needed to satisfy interface
>>> requirements:
>>>
>>>> interface Foo{ int bar(); }
>>>> class A { int baz(){return 1;} }
>>>> class B : A, Foo{ alias A.baz bar;}
>>>> void main(){}
>>> I don't think this will work, and the only way around it is:
>>>
>>>> class B : A, Foo{ int bar(){return baz();} }
>>
>> That's what I've been doing, but now that -profile is telling me bar is
>> one of the largest time consumers in the program, I'm going back to trying
>> to get aliasing to work (it was suggested on this mailing list in a past
>> thread of the same title).
>>
>> Using the terms from your example, bar is called 10x more than any other
>> function. The baz function is really simple (almost as simple as "return
>> 1"). The total time per call is only 1 tick (microsecond). Maybe it's
>> just a fluke with the profiling, or maybe it really is significant. I
>> wanted to try the alias trick to see if it'd drop it in the overal
>> profiler output.
>
> A function that only calls another function and returns that result should
> at LEAST be optimized to a call/ret instruction pair. A good compiler will
> optimize it to a jump instruction. If the compiler is clever enough, it
> will be inlined and you won't even notice that it is calling a different
> function. I don't think that is your problem. If it's possible, you could
> post the code or a trimmed down version that has the same problem, and
> someone may have a good solution for you.
>
> -Steve
Did you compile with the -inline flag?
--bb
More information about the Digitalmars-d-learn
mailing list