Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Small optimization
Small optimization [message #57056] Tue, 18 May 2021 15:36 Go to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hello Mirek,

I have a small optimisation proposition for cases where fundamental data types are used

in Vcont.h

Replace:
template <class T>
inline void Construct(T *t, const T *lim) {
	while(t < lim)
		new(t++) T;
}



with:
template <class T>
inline void Construct(T *t, const T *lim) {
	if ( ! std::is_fundamental<T>::value ) {
		while(t < lim)
			new(t++) T;
	}
}


Other methods near this one can benefit from this small optimisation (Destroy for example)

Note: Tested on my app : everything seems to work fine

[Updated on: Tue, 18 May 2021 16:58]

Report message to a moderator

Re: Small optimization [message #57119 is a reply to message #57056] Thu, 27 May 2021 09:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Didier wrote on Tue, 18 May 2021 15:36
Hello Mirek,

I have a small optimisation proposition for cases where fundamental data types are used

in Vcont.h

Replace:
template <class T>
inline void Construct(T *t, const T *lim) {
	while(t < lim)
		new(t++) T;
}



with:
template <class T>
inline void Construct(T *t, const T *lim) {
	if ( ! std::is_fundamental<T>::value ) {
		while(t < lim)
			new(t++) T;
	}
}


Other methods near this one can benefit from this small optimisation (Destroy for example)

Note: Tested on my app : everything seems to work fine


I am not fundamentally against it, but I am pretty sure that compiler already optimizes that out as dead code - which means it is just added noise.

never_inline
void Foo() {
	RLOG("---");
}

CONSOLE_APP_MAIN
{
	int x[4];
	Foo();
	Construct(x, x + 4);
	Foo();
}


400018B0  sub rsp,byte +0x28 
400018B4  call dword 0x1400017e0 // call to Foo
400018B9  nop // this to align
400018BA  add rsp,byte +0x28 
400018BE  jmp dword 0x1400017e0 // call to Foo


Mirek
Re: Small optimization [message #57125 is a reply to message #57119] Thu, 27 May 2021 20:01 Go to previous message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
You are perfectly right then: clearner code is better Thumbs Up
Previous Topic: DarkThemeCached
Next Topic: SIGPIPE problem
Goto Forum:
  


Current Time: Fri Mar 29 08:54:06 CET 2024

Total time taken to generate the page: 0.01743 seconds