Repository navigation
Conversation
|
In ToolDock and TimeTrack, what was the real intent? Are you sure those fixes are the correct ones? |
|
The affected code in ToolDock and TimeTrack wasn't touched in years, we can only guess what originally was intended. |
There was a problem hiding this comment.
Not really sure what this is needed???
There was a problem hiding this comment.
It's an optimization. Initialization lists are a little bit faster than assigning the value in the constructor body. And as one value already uses the initialization list, I simply moved that one over there too. ;)
There was a problem hiding this comment.
Just tried this in g++ with -O3 specified:
class inconstructor
{
public:
inconstructor(int parm1)
{
mParm = parm1;
}
public:
int mParm;
};
class ininitializer
{
public:
ininitializer(int parm1)
: mParm(parm1)
{
}
public:
int mParm;
};
inconstructor tryc(123);
ininitializer tryi(456);And here is what the compiler produced:
.file "t.cpp"
.section .text.startup,"x"
.p2align 4,,15
.def _GLOBAL__sub_I_tryc; .scl 3; .type 32; .endef
.seh_proc _GLOBAL__sub_I_tryc
_GLOBAL__sub_I_tryc:
.LFB7:
.seh_endprologue
movl $123, tryc(%rip)
movl $456, tryi(%rip)
ret
.seh_endproc
.section .ctors,"w"
.align 8
.quad _GLOBAL__sub_I_tryc
.globl tryi
.bss
.align 4
tryi:
.space 4
.globl tryc
.align 4
tryc:
.space 4
.ident "GCC: (GNU) 4.9.2"Looks about the same to me...
There was a problem hiding this comment.
Probably because gcc can automatically optimize it for integers, but on more complex objects, this can slightly increase performance, see http://www.tantalon.com/pete/cppopt/asyougo.htm#UseConstructorInitializationLists
There was a problem hiding this comment.
I'll give it a read in a bit, but here's one using an object:
class morecomplex
{
public:
morecomplex()
{
}
morecomplex(int parm)
{
mParm = parm;
}
public:
int mParm;
};
class inconstructor
{
public:
inconstructor(morecomplex parm1)
{
mParm = parm1;
}
public:
morecomplex mParm;
};
class ininitializer
{
public:
ininitializer(morecomplex parm1)
: mParm(parm1)
{
}
public:
morecomplex mParm;
};
extern morecomplex trycc;
extern morecomplex tryci;
inconstructor tryc(trycc);
ininitializer tryi(tryci);
And the results:
.file "t.cpp"
.section .text.startup,"x"
.p2align 4,,15
.def _GLOBAL__sub_I_tryc; .scl 3; .type 32; .endef
.seh_proc _GLOBAL__sub_I_tryc
_GLOBAL__sub_I_tryc:
.LFB13:
.seh_endprologue
movq .refptr.trycc(%rip), %rax
movl (%rax), %eax
movl %eax, tryc(%rip)
movq .refptr.tryci(%rip), %rax
movl (%rax), %eax
movl %eax, tryi(%rip)
ret
.seh_endproc
.section .ctors,"w"
.align 8
.quad _GLOBAL__sub_I_tryc
.globl tryi
.bss
.align 4
tryi:
.space 4
.globl tryc
.align 4
tryc:
.space 4
.ident "GCC: (GNU) 4.9.2"
.section .rdata$.refptr.tryci, "dr"
.globl .refptr.tryci
.linkonce discard
.refptr.tryci:
.quad tryci
.section .rdata$.refptr.trycc, "dr"
.globl .refptr.trycc
.linkonce discard
.refptr.trycc:
.quad trycc
Again, I haven't yet read the article at the provided link yet, but seems to me that, so far, they are the same.
There was a problem hiding this comment.
Just tried it with an even more complex "morecomplex" class:
class morecomplex
{
public:
morecomplex()
: mParm(0),
sss({2, 3, 4.f, 9.0})
{
}
morecomplex(int parm)
{
mParm = parm;
}
public:
int mParm;
char buffer[1234];
struct
{
int a;
int b;
float f;
double d;
} sss;
};
And the results were exactly the same again. Weird...wonder why the guys results were so much better...maybe something to do with templates?
There was a problem hiding this comment.
That documentation is pretty old, might be that compilers are a lot smarter than they were back when that document was written… I guess it is not an optimization then, only a style change.
But still, cppcheck suggests to change it.
|
My mistake, it is a pull request, not just a commit. Rejected in its current form. Dan, come on over to audacity-devel e-mail list and we can talk about style in audacity and what an acceptable pull request would need. |
No description provided.