You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by hz...@apache.org on 2016/02/01 22:49:37 UTC
[5/9] incubator-trafodion git commit: refine the iconv function,
remove unnecessary code to boost perf further
refine the iconv function, remove unnecessary code to boost perf further
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/aecc2db1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/aecc2db1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/aecc2db1
Branch: refs/heads/master
Commit: aecc2db1d76b1f030fc115060a2ad27de4802f65
Parents: 82b256c
Author: Liu Ming <mi...@esgyn.cn>
Authored: Wed Jan 13 14:09:26 2016 +0000
Committer: Liu Ming <mi...@esgyn.cn>
Committed: Wed Jan 13 14:09:26 2016 +0000
----------------------------------------------------------------------
core/sql/common/csconvert.cpp | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/aecc2db1/core/sql/common/csconvert.cpp
----------------------------------------------------------------------
diff --git a/core/sql/common/csconvert.cpp b/core/sql/common/csconvert.cpp
index 438ee8b..2423976 100644
--- a/core/sql/common/csconvert.cpp
+++ b/core/sql/common/csconvert.cpp
@@ -1281,21 +1281,24 @@ char * findStartOfChar( char *someByteInChar, char *startOfBuffer )
}
/* A method to do character set conversion , using Glibc iconv */
-static int code_convert(const char *from_charset,const char *to_charset,char *inbuf, size_t inlen, char *outbuf,size_t outlen)
+static int charsetConvert(const char *srcCharset,const char *targetCharset,char *inputbuf, size_t inputlen, char *outbuf,size_t outlen)
{
+ char **ptrin = &inputbuf;
+ char **ptrout = &outbuf;
+
iconv_t cd;
- int rc;
- char **pin = &inbuf;
- char **pout = &outbuf;
-
- cd = iconv_open(to_charset,from_charset);
- if (cd==0) return -1;
- memset(outbuf,0,outlen);
- if (iconv(cd,pin,(size_t*)&inlen,pout,(size_t *)&outlen)==-1)
+ cd = iconv_open(targetCharset,srcCharset);
+
+ if (cd==0)
+ return -1;
+
+ if (iconv(cd,ptrin,(size_t*)&inputlen,ptrout,(size_t *)&outlen) == -1)
{
+ //error occurs
iconv_close(cd);
return -1;
}
+
iconv_close(cd);
return outlen;
}
@@ -1305,14 +1308,15 @@ int gbkToUtf8(char* gbkString, size_t gbklen,
char* result ,size_t outlen, bool addNullAtEnd)
{
int originalOutlen = outlen;
- int finalLength = code_convert( "gbk","utf-8", gbkString, gbklen, result, outlen);
+ int finalLength = charsetConvert( "gbk","utf-8", gbkString, gbklen, result, outlen);
- if (finalLength == -1 ) return 0;
+ if (finalLength == -1 )
+ return 0;
if ( addNullAtEnd )
{
- if(originalOutlen >= finalLength )
- result[finalLength] = 0;
+ if(originalOutlen >= finalLength )
+ result[finalLength] = 0;
}
return finalLength;