[GRASS5] segment lib speed patch
Markus Neteler
neteler at itc.it
Tue Jun 28 04:15:48 EDT 2005
Hi,
I got some useful offlist comments. Find attached the modified
patch along with the suggested HAVE_LSEEK condition.
The '\n' were old stuff, I have taken them out.
Please have a look again.
Markus
On Mon, Jun 27, 2005 at 02:04:40PM -0700, Brad Douglas wrote:
> On Mon, 2005-06-27 at 17:03 +0200, Markus Neteler wrote:
> > Hi,
> >
> > to speed up the creation of segments in lib/segment/format.c,
> > a colleague from ITC-irst proposes the attached patch.
> > I used it locally for quite a while without having problems.
> >
> > I would like to hear you opinion:
> > - any objections to include it (removing the old version)?
> > - should it be conditionalized for GNU/Linux only or
> > anything else (means: modifying the current condition ORIG)?
>
> It's a basic POSIX function, so you're safe. If you want to get
> technical about it, then you could surround it with #ifdef HAVE_LSEEK...
> generated by autoconf, which may arguably be better than #ifdef ORIG...
>
> PS -
> You don't need the '\n' in G_warning(), unless you intend on a double
> carriage return.
>
>
> --
> Brad Douglas <rez at touchofmadness.com>
>
--
Markus Neteler <neteler itc it> http://mpa.itc.it
ITC-irst - Centro per la Ricerca Scientifica e Tecnologica
MPBA - Predictive Models for Biol. & Environ. Data Analysis
Via Sommarive, 18 - 38050 Povo (Trento), Italy
-------------- next part --------------
Index: format.c
===================================================================
RCS file: /grassrepository/grass6/lib/segment/format.c,v
retrieving revision 2.0
diff -u -r2.0 format.c
--- format.c 9 Nov 2004 13:09:30 -0000 2.0
+++ format.c 28 Jun 2005 08:11:07 -0000
@@ -3,6 +3,7 @@
#include <errno.h>
#include <unistd.h>
#include "segment.h"
+#include "config.h"
static int _segment_format (int,int,int,int,int,int,int);
static int write_int(int,int);
@@ -60,14 +61,14 @@
if (nrows <= 0 || ncols <= 0 || len <= 0 || srows <= 0 || scols <= 0)
{
G_warning (
- "segement_format(fd,%d,%d,%d,%d,%d): illegal value(s)\n",
+ "segment_format(fd,%d,%d,%d,%d,%d): illegal value(s)",
nrows, ncols, srows, scols, len);
return -3;
}
if (lseek (fd, 0L, 0) == (off_t)-1)
{
- G_warning ("Segment_format: %s\n",strerror(errno));
+ G_warning ("Segment_format: %s",strerror(errno));
return -1;
}
@@ -107,12 +108,13 @@
x = n;
if((bytes_wrote = write (fd, &x, sizeof(int)) == sizeof(int) ) < 0)
- G_warning("%s\n",strerror(errno));
+ G_warning("%s",strerror(errno));
return bytes_wrote;
}
static int zero_fill(int fd, long nbytes)
{
+#ifndef HAVE_LSEEK
char buf[10240];
register char *b;
register int n;
@@ -127,10 +129,25 @@
{
n = nbytes > sizeof(buf) ? sizeof(buf) : nbytes ;
if(write (fd, buf, n) != n) {
- G_warning("%s\n",strerror(errno));
+ G_warning("%s",strerror(errno));
return -1;
}
nbytes -= n;
}
return 1;
+#else
+ char buf[10];
+
+ buf[0]=0x0;
+ G_debug(3,"Using new segmentation code...");
+ if ( lseek(fd,nbytes-1,SEEK_SET) < 0 ) {
+ G_warning("%s",strerror(errno));
+ return -1;
+ }
+ if(write (fd,buf, 1) != 1) {
+ G_warning("%s",strerror(errno));
+ return -1;
+ }
+ return 1;
+#endif
}
More information about the grass-dev
mailing list