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 » Community » U++ community news and announcements » String & strlen optimization, force_inline in defs.h
String & strlen optimization, force_inline in defs.h [message #34620] Fri, 02 December 2011 09:53 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
When strlen is intrinsic and applied to string literal, both compilers are able to replace it with constant.

That has a huge impact when we do things like

String s = "Hello ";
s << "world!";

because it is possible that we completely avoid scanning literal for its length (second command is then equivalent to Cat("world!", 6)).

Now this always worked (without me actually knowing Wink quite well in GCC, except some String methods that did have strlen hidden in .cpp file.

Not so easy with MSC, which stubbornly refuses to inline some things and needs strlen to be activated as intrinsics.

Anyway, by combination of techniques, both compiler should be now able to optimize out strlen in most common cases.

In the process, I have added "force_inline" macro (thanks for hinting that out, Novo) to hide differences between MSC (__force_inline) and GCC (declspace(always_inline) inline).

Mirek
Re: String & strlen optimization, force_inline in defs.h [message #34638 is a reply to message #34620] Fri, 02 December 2011 19:57 Go to previous message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Another trick:

template <int N> 
int strlen__(const char (&s)[N]) { return N; }

Cout() << strlen__("asdf") << EOL;


Regards,
Novo
Previous Topic: svn and redmine urls
Next Topic: Sql: New 'Of' 'syntax'
Goto Forum:
  


Current Time: Mon Apr 29 06:05:39 CEST 2024

Total time taken to generate the page: 0.05779 seconds