[Mono-devel-list] Npgsql patch for binary types

Francisco Figueiredo Jr. fxjrlists at yahoo.com.br
Thu Oct 23 11:14:51 EDT 2003


Jackson Harper wrote:
> Hello,
> 

Hi Jackson!

> 	Attached is a patch to NpgsqlTypes/NpgswlTypesHelper.cs that allows
> binary types to be used as parameters. Is it ok to commit?
> 

Thanks!

We now have two implementations for this.

This is the implementation which we already have in cvs:


private static String ConvertByteArrayToBytea(Byte[] byteArray)
         {
         NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, 	 
"ConvertByteArrayToBytea");
                 StringBuilder  result = new StringBuilder(""); 


                 foreach(Byte byteToConvert in byteArray)
                 {
                         result.Append("\\\\");
                         result.Append((byteToConvert & 0xC0) >> 6);
                         result.Append((byteToConvert & 0x38) >> 3);
                         result.Append(byteToConvert & 0x07);
                 }

                 return result.ToString();
         }


But I don't know yet if yours could be faster. We have to do somet 
tests. I know that the current implementation isn't so fast. I mean, it 
is using byte shifts and I don't know how much slower or faster it could 
be compared to "ifs".


Also, we have the inverse operation and I'm sure this has a lot of space 
for optimizations. Please have a look in the ConvertyByteAToByteArray 
method. The problem there is to convert a string in octal form \\201 for 
example in its byte value. This method is very slow and consuming a lot 
of memory when the value to be converted is larger than 2 megabytes.

Does anybody know some good way of converting a string value in octal to 
its byte value?

> Thanks,

Thank you Jackson.

Regards,

Francisco Figueiredo Jr.




More information about the Mono-devel-list mailing list