We can avoid converting UV to text when it fits in int64.
Test fails before patch only on machines with 32-bit IV/UV.
>From a8b7660ef9ea6c0f14b9c2ab50719b837e233822 Mon Sep 17 00:00:00 2001
From: "Yuriy M. Kaminskiy" <[email protected]>
Date: Sat, 24 Mar 2012 17:22:32 +0400
Subject: [PATCH 2/3] Convert unsigned -> int64 when possible
It is not necessary to convert UV to text when sizeof(UV) < sizeof(int64_t)
---
dbdimp.c | 4 ++++
t/09_create_function.t | 5 ++++-
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/dbdimp.c b/dbdimp.c
index 26872be..ff69459 100644
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -142,8 +142,12 @@ sqlite_set_result(pTHX_ sqlite3_context *context, SV *result, int is_error)
if ( !SvOK(result) ) {
sqlite3_result_null( context );
} else if( SvIOK_UV(result) ) {
+ if ((UV)(sqlite3_int64)UV_MAX == UV_MAX)
+ sqlite3_result_int64( context, (sqlite3_int64)SvUV(result));
+ else {
s = SvPV(result, len);
sqlite3_result_text( context, s, len, SQLITE_TRANSIENT );
+ }
}
else if ( SvIOK(result) ) {
#if defined(USE_64_BIT_INT)
diff --git a/t/09_create_function.t b/t/09_create_function.t
index 090fb73..a868b5b 100644
--- a/t/09_create_function.t
+++ b/t/09_create_function.t
@@ -11,7 +11,7 @@ use t::lib::Test qw/connect_ok @CALL_FUNCS/;
use Test::More;
use Test::NoWarnings;
-plan tests => 28 * @CALL_FUNCS + 1;
+plan tests => 29 * @CALL_FUNCS + 1;
sub now {
return time();
@@ -123,5 +123,8 @@ foreach my $call_func (@CALL_FUNCS) {
$result = $dbh->selectrow_arrayref( "SELECT noop(2147483648)" );
is_deeply( $result, [ 2147483648 ], "SELECT noop(2147483648)" );
+ $result = $dbh->selectrow_arrayref( "SELECT typeof(noop(2147483648))" );
+ is_deeply( $result, [ 'integer' ], "SELECT typeof(noop(2147483648))" );
+
$dbh->disconnect;
}
--
1.7.6.3
>From 6e4cb79d28a38272f83ce878c41902143295490d Mon Sep 17 00:00:00 2001
From: "Yuriy M. Kaminskiy" <[email protected]>
Date: Sat, 24 Mar 2012 20:21:04 +0400
Subject: [PATCH 3/3] reindent
---
dbdimp.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/dbdimp.c b/dbdimp.c
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -145,8 +145,8 @@ sqlite_set_result(pTHX_ sqlite3_context *context, SV *result, int is_error)
if ( (UV)(sqlite3_int64)UV_MAX == UV_MAX )
sqlite3_result_int64( context, (sqlite3_int64)SvUV( result ) );
else {
- s = SvPV(result, len);
- sqlite3_result_text( context, s, len, SQLITE_TRANSIENT );
+ s = SvPV(result, len);
+ sqlite3_result_text( context, s, len, SQLITE_TRANSIENT );
}
}
else if ( SvIOK(result) ) {
--
1.7.6.3
_______________________________________________
DBD-SQLite mailing list
[email protected]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbd-sqlite