Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: Bug: char[]s not escaped

From: Jonathan Wakely <jonathan.wakely(at)gmail.com>
Date: Tue Jul 03 2007 - 20:20:46 EDT


On 02/07/07, Andrew Sayers <andrew-mysqlpp@pileofstuff.org> wrote:
>
> +inline std::ostream& operator <<(quote_type1 o,
> + char in[])
> +{
> + return operator <<(o, static_cast<const char* const&>(in));
> +}

Personally I would use simply static_cast<cont char*>(in) if doing that.

It is a direct conversion from char[] to char* and last time I saw any benchmarks it was cheaper to copy a pointer a reference (and it will be copied by value when passed to the operator<< function anyway.) The assembly code shows five instructions for the reference version and two otherwise.

Alternatively, something like

template <int N>
inline std::ostream& operator <<(quote_type1 o, const char (&in)[N]) {

       return o.ostr->write(in, N-1); // don't write nul terminator }

You know the size of the array, why discard that info and require a strlen call? The const overloads aren't needed, char[N] will match const char[N] rather than the default specialisation, so you only need one overload for quote_type1 and one for escape_type1.

Jon

-- 
MySQL++ Mailing List
For list archives: 
http://lists.mysql.com/plusplus
To unsubscribe:    
http://lists.mysql.com/plusplus?unsub=lists@pantek.com
Received on Tue Jul 3 20:21:11 2007
Do you need help?X

This archive was generated by hypermail 2.1.8 : Tue Jul 03 2007 - 20:30:02 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library