Subject: | A little performance improvement |
Hello,
I have written a patch to use PERL_NO_GET_CONTEXT for efficiency, which
makes CSV_XS a little faster, especially some platforms, i.g. Cygwin
with ithreads.
The patch includes some other changes: some unused variables removed and
using newSVpvs() instead of newSVpv() in .
Regards,
--
Goro Fuji (GFUJI at CPAN.org)
Subject: | CSV_XS.diff |
*** CSV_XS.xs~ Sun Jan 18 19:43:28 2009
--- CSV_XS.xs Sun Jan 18 23:43:14 2009
***************
*** 3,9 ****
* This program is free software; you can redistribute it and/or
* modify it under the same terms as Perl itself.
*/
!
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
--- 3,9 ----
* This program is free software; you can redistribute it and/or
* modify it under the same terms as Perl itself.
*/
! #define PERL_NO_GET_CONTEXT
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
***************
*** 172,183 ****
unless (io_handle_loaded) { \
ENTER; \
load_module (PERL_LOADMOD_NOIMPORT, \
! newSVpv ("IO::Handle", 0), NULL, NULL, NULL); \
LEAVE; \
io_handle_loaded = 1; \
}
! static SV *SvDiag (int xse)
{
int i = 0;
SV *err;
--- 172,186 ----
unless (io_handle_loaded) { \
ENTER; \
load_module (PERL_LOADMOD_NOIMPORT, \
! newSVpvs ("IO::Handle"), NULL, NULL, NULL); \
LEAVE; \
io_handle_loaded = 1; \
}
! static SV* m_getline;
!
! #define SvDiag(xse) cx_SvDiag(aTHX_ xse)
! static SV *cx_SvDiag (pTHX_ int xse)
{
int i = 0;
SV *err;
***************
*** 191,199 ****
return (err);
} /* SvDiag */
! static SV *SetDiag (csv_t *csv, int xse)
{
- int i = 0;
SV *err = SvDiag (xse);
if (err) {
--- 194,202 ----
return (err);
} /* SvDiag */
! #define SetDiag(csv, xse) cx_SetDiag(aTHX_ csv, xse)
! static SV *cx_SetDiag (pTHX_ csv_t *csv, int xse)
{
SV *err = SvDiag (xse);
if (err) {
***************
*** 206,212 ****
return (err);
} /* SetDiag */
! static void SetupCsv (csv_t *csv, HV *self)
{
SV **svp;
STRLEN len;
--- 209,216 ----
return (err);
} /* SetDiag */
! #define SetupCsv(csv, self) cx_SetupCsv(aTHX_ csv, self)
! static void cx_SetupCsv (pTHX_ csv_t *csv, HV *self)
{
SV **svp;
STRLEN len;
***************
*** 355,361 ****
csv->used = 0;
} /* SetupCsv */
! static int Print (csv_t *csv, SV *dst)
{
int result;
--- 359,366 ----
csv->used = 0;
} /* SetupCsv */
! #define Print(csv, dst) cx_Print(aTHX_ csv, dst)
! static int cx_Print (pTHX_ csv_t *csv, SV *dst)
{
int result;
***************
*** 399,405 ****
/* Should be extended for EBCDIC ? */
#define is_csv_binary(ch) ((ch < CH_SPACE || ch >= CH_DEL) && ch != CH_TAB)
! static int Combine (csv_t *csv, SV *dst, AV *fields)
{
int i;
--- 404,411 ----
/* Should be extended for EBCDIC ? */
#define is_csv_binary(ch) ((ch < CH_SPACE || ch >= CH_DEL) && ch != CH_TAB)
! #define Combine(csv, dst, fields) cx_Combine(aTHX_ csv, dst, fields)
! static int cx_Combine (pTHX_ csv_t *csv, SV *dst, AV *fields)
{
int i;
***************
*** 495,501 ****
#if MAINT_DEBUG
static char str_parsed[40];
#endif
! static void ParseError (csv_t *csv, int xse, int pos)
{
hv_store (csv->self, "_ERROR_POS", 10, newSViv (pos), 0);
if (csv->tmp) {
--- 501,509 ----
#if MAINT_DEBUG
static char str_parsed[40];
#endif
!
! #define ParseError(csv, xse, pos) cx_ParseError(aTHX_ csv, xse, pos)
! static void cx_ParseError (pTHX_ csv_t *csv, int xse, int pos)
{
hv_store (csv->self, "_ERROR_POS", 10, newSViv (pos), 0);
if (csv->tmp) {
***************
*** 505,511 ****
(void)SetDiag (csv, xse);
} /* ParseError */
! static int CsvGet (csv_t *csv, SV *src)
{
unless (csv->useIO)
return EOF;
--- 513,520 ----
(void)SetDiag (csv, xse);
} /* ParseError */
! #define CsvGet(csv, src) cx_CsvGet(aTHX_ csv, src)
! static int cx_CsvGet (pTHX_ csv_t *csv, SV *src)
{
unless (csv->useIO)
return EOF;
***************
*** 520,526 ****
EXTEND (sp, 1);
PUSHs (src);
PUTBACK;
! result = call_method ("getline", G_SCALAR);
SPAGAIN;
csv->tmp = result ? POPs : NULL;
PUTBACK;
--- 529,535 ----
EXTEND (sp, 1);
PUSHs (src);
PUTBACK;
! result = call_sv (m_getline, G_SCALAR | G_METHOD);
SPAGAIN;
csv->tmp = result ? POPs : NULL;
PUTBACK;
***************
*** 607,613 ****
}
#endif
! static void strip_trail_whitespace (SV *sv)
{
STRLEN len;
char *s = SvPV (sv, len);
--- 616,623 ----
}
#endif
! #define strip_trail_whitespace(sv) cx_strip_trail_whitespace(aTHX_ sv)
! static void cx_strip_trail_whitespace (pTHX_ SV *sv)
{
STRLEN len;
char *s = SvPV (sv, len);
***************
*** 618,624 ****
SvCUR_set (sv, len);
} /* strip_trail_whitespace */
! static SV *bound_field (csv_t *csv, int i)
{
SV *sv = csv->bound;
AV *av;
--- 628,635 ----
SvCUR_set (sv, len);
} /* strip_trail_whitespace */
! #define bound_field(csv, i) cx_bound_field(aTHX_ csv, i)
! static SV *cx_bound_field (pTHX_ csv_t *csv, int i)
{
SV *sv = csv->bound;
AV *av;
***************
*** 655,661 ****
f = 0; \
}
! static int Parse (csv_t *csv, SV *src, AV *fields, AV *fflags)
{
int c, f = 0;
int c_ungetc = EOF;
--- 666,673 ----
f = 0; \
}
! #define Parse(csv, src, fields, fflags) cx_Parse(aTHX_ csv, src, fields, fflags)
! static int cx_Parse (pTHX_ csv_t *csv, SV *src, AV *fields, AV *fflags)
{
int c, f = 0;
int c_ungetc = EOF;
***************
*** 1077,1083 ****
return TRUE;
} /* Parse */
! static int xsParse (HV *hv, AV *av, AV *avf, SV *src, bool useIO)
{
csv_t csv;
int result;
--- 1089,1096 ----
return TRUE;
} /* Parse */
! #define xsParse(hv, av, avf, src, useIO) cx_xsParse(aTHX_ hv, av, avf, src, useIO)
! static int cx_xsParse (pTHX_ HV *hv, AV *av, AV *avf, SV *src, bool useIO)
{
csv_t csv;
int result;
***************
*** 1135,1141 ****
return result;
} /* xsParse */
! static int xsCombine (HV *hv, AV *av, SV *io, bool useIO)
{
csv_t csv;
int result;
--- 1148,1155 ----
return result;
} /* xsParse */
! #define xsCombine(hv, av, io, useIO) cx_xsCombine(aTHX_ hv, av, io, useIO)
! static int cx_xsCombine (pTHX_ HV *hv, AV *av, SV *io, bool useIO)
{
csv_t csv;
int result;
***************
*** 1160,1166 ****
PROTOTYPES: DISABLE
! SV*
SetDiag (self, xse)
SV *self
int xse
--- 1174,1183 ----
PROTOTYPES: DISABLE
! BOOT:
! m_getline = newSVpvs("getline");
!
! void
SetDiag (self, xse)
SV *self
int xse
***************
*** 1179,1185 ****
XSRETURN (1);
/* XS SetDiag */
! SV*
Combine (self, dst, fields, useIO)
SV *self
SV *dst
--- 1196,1202 ----
XSRETURN (1);
/* XS SetDiag */
! void
Combine (self, dst, fields, useIO)
SV *self
SV *dst
***************
*** 1196,1202 ****
XSRETURN (1);
/* XS Combine */
! SV*
Parse (self, src, fields, fflags)
SV *self
SV *src
--- 1213,1219 ----
XSRETURN (1);
/* XS Combine */
! void
Parse (self, src, fields, fflags)
SV *self
SV *src