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 » Some 'missing' string functions
Re: Some 'missing' string functions [message #16313 is a reply to message #16304] Sat, 07 June 2008 16:12 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14267
Registered: November 2005
Ultimate Member
Thanks.

I could not resist but to try this little common-case optimization:

template <class B>
int AString<B>::FindFirstOf(int len, const tchar *s, int from) const
{
	ASSERT(from >= 0 && from <= GetLength());
	const tchar *ptr = B::Begin();
	const tchar *e = End();
	const tchar *se = s + (len * sizeof(tchar));
	if((s[0] & s[1]) != 0) {
		if(s[2] == 0) {
			__BREAK__;
			tchar c1 = s[0];
			tchar c2 = s[1];
			for(const tchar *bs = ptr + from; bs < e; bs++) {
				tchar ch = *bs;
				if(ch == c1 || ch == c2)
					return (int)(bs - ptr);
			}
			return -1;
		}
		if(s[3] == 0) {
			tchar c1 = s[0];
			tchar c2 = s[1];
			tchar c3 = s[2];
			for(const tchar *bs = ptr + from; bs < e; bs++) {
				tchar ch = *bs;
				if(ch == c1 || ch == c2 || ch == c3)
					return (int)(bs - ptr);
			}
			return -1;
		}
		if(s[4] == 0) {
			tchar c1 = s[0];
			tchar c2 = s[1];
			tchar c3 = s[2];
			tchar c4 = s[3];
			for(const tchar *bs = ptr + from; bs < e; bs++) {
				tchar ch = *bs;
				if(ch == c1 || ch == c2 || ch == c3 || ch == c4)
					return (int)(bs - ptr);
			}
			return -1;
		}
	}
	for(const tchar *bs = ptr + from; bs < e; bs++)
		for(const tchar *ss = s; ss < se; ss++)
			if(*bs == *ss)
				return (int)(bs - ptr);
	return -1;
}


Seems to be 2x faster for these "common cases"...

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Commandline-Args with Core-Console-App
Next Topic: Path including non-English character, buglog and usrlog file cannot be deleted
Goto Forum:
  


Current Time: Mon Aug 25 16:58:30 CEST 2025

Total time taken to generate the page: 0.05268 seconds