Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
ToDo plugin patch doing some refactoring
frithjofh:
for the speed argument between subscript and GetChar() on wxString i put this quote from wxWidgets:
--- Quote ---Reference counting and why you shouldn't care about it
All considerations for wxObject-derived reference counted objects are valid also for wxString, even if it does not derive from wxObject.
Probably the unique case when you might want to think about reference counting is when a string character is taken from a string which is not a constant (or a constant reference). In this case, due to C++ rules, the "read-only" operator[] (which is the same as GetChar()) cannot be chosen and the "read/write" operator[] (the same as GetWritableChar()) is used instead. As the call to this operator may modify the string, its data is unshared (COW is done) and so if the string was really shared there is some performance loss (both in terms of speed and memory consumption). In the rare cases when this may be important, you might prefer using GetChar() instead of the array subscript operator for this reasons. Please note that at() method has the same problem as the subscript operator in this situation and so using it is not really better. Also note that if all string arguments to your functions are passed as const wxString& (see the section Some advice) this situation will almost never arise because for constant references the correct operator is called automatically.
--- End quote ---
as buffer is a const wxString& there should be no difference. But I will do a measurement after Christmas or when ever I will have time...
ollydbg:
Thanks for the clarification.
I think I will handle those patches after our 15.12 release. You can just ping on this thread if I forget about it. :)
MortenMacFly:
--- Quote from: ollydbg on December 05, 2015, 03:39:16 pm ---What is the difference between
--- Code: ---buffer.GetChar(pos)
--- End code ---
and
--- Code: ---buffer[pos]
--- End code ---
If I remember correctly, in our CodeCompletion's code, it use GetChar, does it have performance issue? Since the operator return a reference?
--- End quote ---
IMHO the difference is that the first one is checked, the other one not and therefore a potential crash candidate.
frithjofh:
if GetChar() is checked, then it must be slower than subscript...
What would be the right decision? Crash candidate or speed? Using subscript the function surely could be written so, that pos must always be a valid index into buffer, with only one check for validity some place...
Is GetChar() really checked? I couldn’t find anything about it (that means, I may just not know, where to look...)
MortenMacFly:
--- Quote from: frithjofh on December 13, 2015, 06:36:52 pm ---Is GetChar() really checked? I couldn’t find anything about it (that means, I may just not know, where to look...)
--- End quote ---
Check wx/string.h:
--- Code: (cpp) --- wxChar GetChar(size_t n) const
{ return at(n); }
--- End code ---
...later on:
--- Code: (cpp) --- value_type at(size_type n) const
{ wxASSERT_VALID_INDEX( n ); return m_pchData[n]; }
--- End code ---
The assert macro is probably "nothing" in release builds. But it helps debugging in debug builds.
Please use GetChar. We handle many files, make complex parsing, may encounter weird encodings - its the best you can do it such situation.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version