[GRASS-SVN] r49548 - grass/trunk/lib/segment

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Dec 5 07:49:48 EST 2011


Author: mmetz
Date: 2011-12-05 04:49:48 -0800 (Mon, 05 Dec 2011)
New Revision: 49548

Modified:
   grass/trunk/lib/segment/address.c
   grass/trunk/lib/segment/get.c
   grass/trunk/lib/segment/get_row.c
   grass/trunk/lib/segment/pagein.c
   grass/trunk/lib/segment/pageout.c
   grass/trunk/lib/segment/put.c
   grass/trunk/lib/segment/put_row.c
   grass/trunk/lib/segment/seek.c
   grass/trunk/lib/segment/setup.c
Log:
segment lib cosmetics: update adress / seek fn calls

Modified: grass/trunk/lib/segment/address.c
===================================================================
--- grass/trunk/lib/segment/address.c	2011-12-05 12:48:56 UTC (rev 49547)
+++ grass/trunk/lib/segment/address.c	2011-12-05 12:49:48 UTC (rev 49548)
@@ -35,7 +35,7 @@
 	*n = col >> SEG->scolbits;
 	*index = col - ((*n) << SEG->scolbits);
     }
-    if (SEG->slow_seek == 0)
+    if (!SEG->slow_seek)
 	*index = *index << SEG->lenbits;
     else
 	*index *= SEG->len;
@@ -51,9 +51,8 @@
 	int seg_c = col / SEG->scols;
 
 	*n = seg_r * SEG->spr + seg_c;
-	*index =
-	    (row - seg_r * SEG->srows) * SEG->scols + col -
-	    seg_c * SEG->scols;
+	*index = (row - seg_r * SEG->srows) * SEG->scols + col -
+		 seg_c * SEG->scols;
     }
     /* for simple arrays */
     else {
@@ -65,9 +64,6 @@
     return 0;
 }
 
-static int (*segment_adrs[2]) () = {
-segment_address_fast, segment_address_slow};
-
 /**
  * \fn int segment_address (SEGMENT *SEG, int row, int col, int *n, int *index)
  *
@@ -91,5 +87,5 @@
     /* this function is called at least once every time data are accessed in SEG
      * avoid very slow modulus and divisions, modulus was the main time killer */
 
-    return (*segment_adrs[SEG->slow_adrs]) (SEG, row, col, n, index);
+    return SEG->segment_address(SEG, row, col, n, index);
 }

Modified: grass/trunk/lib/segment/get.c
===================================================================
--- grass/trunk/lib/segment/get.c	2011-12-05 12:48:56 UTC (rev 49547)
+++ grass/trunk/lib/segment/get.c	2011-12-05 12:49:48 UTC (rev 49548)
@@ -42,7 +42,7 @@
 {
     int index, n, i;
 
-    segment_address(SEG, row, col, &n, &index);
+    SEG->segment_address(SEG, row, col, &n, &index);
     if ((i = segment_pagein(SEG, n)) < 0)
 	return -1;
 

Modified: grass/trunk/lib/segment/get_row.c
===================================================================
--- grass/trunk/lib/segment/get_row.c	2011-12-05 12:48:56 UTC (rev 49547)
+++ grass/trunk/lib/segment/get_row.c	2011-12-05 12:49:48 UTC (rev 49548)
@@ -52,8 +52,8 @@
     size = scols * SEG->len;
 
     for (col = 0; col < ncols; col += scols) {
-	segment_address(SEG, row, col, &n, &index);
-	if (segment_seek(SEG, n, index) < 0)
+	SEG->segment_address(SEG, row, col, &n, &index);
+	if (SEG->segment_seek(SEG, n, index) < 0)
 	    return -1;
 
 	if (read(SEG->fd, buf, size) != size) {
@@ -69,8 +69,8 @@
 	buf = ((char *)buf) + size;
     }
     if ((size = SEG->spill * SEG->len)) {
-	segment_address(SEG, row, col, &n, &index);
-	if (segment_seek(SEG, n, index) < 0)
+	SEG->segment_address(SEG, row, col, &n, &index);
+	if (SEG->segment_seek(SEG, n, index) < 0)
 	    return -1;
 
 	if (read(SEG->fd, buf, size) != size) {

Modified: grass/trunk/lib/segment/pagein.c
===================================================================
--- grass/trunk/lib/segment/pagein.c	2011-12-05 12:48:56 UTC (rev 49547)
+++ grass/trunk/lib/segment/pagein.c	2011-12-05 12:49:48 UTC (rev 49548)
@@ -90,7 +90,7 @@
     /* read in the segment */
     SEG->scb[cur].n = n;
     SEG->scb[cur].dirty = 0;
-    segment_seek(SEG, SEG->scb[cur].n, 0);
+    SEG->segment_seek(SEG, SEG->scb[cur].n, 0);
 
     read_result = read(SEG->fd, SEG->scb[cur].buf, SEG->size);
     if (read_result != SEG->size) {

Modified: grass/trunk/lib/segment/pageout.c
===================================================================
--- grass/trunk/lib/segment/pageout.c	2011-12-05 12:48:56 UTC (rev 49547)
+++ grass/trunk/lib/segment/pageout.c	2011-12-05 12:49:48 UTC (rev 49548)
@@ -36,7 +36,7 @@
 
 int segment_pageout(SEGMENT * SEG, int i)
 {
-    segment_seek(SEG, SEG->scb[i].n, 0);
+    SEG->segment_seek(SEG, SEG->scb[i].n, 0);
     if (write(SEG->fd, SEG->scb[i].buf, SEG->size) != SEG->size) {
 	G_warning("segment_pageout: %s", strerror(errno));
 	return -1;

Modified: grass/trunk/lib/segment/put.c
===================================================================
--- grass/trunk/lib/segment/put.c	2011-12-05 12:48:56 UTC (rev 49547)
+++ grass/trunk/lib/segment/put.c	2011-12-05 12:49:48 UTC (rev 49548)
@@ -46,7 +46,7 @@
 {
     int index, n, i;
 
-    segment_address(SEG, row, col, &n, &index);
+    SEG->segment_address(SEG, row, col, &n, &index);
     if ((i = segment_pagein(SEG, n)) < 0) {
 	G_warning("segment lib: put: pagein failed");
 	return -1;

Modified: grass/trunk/lib/segment/put_row.c
===================================================================
--- grass/trunk/lib/segment/put_row.c	2011-12-05 12:48:56 UTC (rev 49547)
+++ grass/trunk/lib/segment/put_row.c	2011-12-05 12:49:48 UTC (rev 49548)
@@ -57,8 +57,8 @@
     /*      printf("segment_put_row ncols: %d, scols %d, size: %d, col %d, row: %d,  SEG->fd: %d\n",ncols,scols,size,col,row, SEG->fd); */
 
     for (col = 0; col < ncols; col += scols) {
-	segment_address(SEG, row, col, &n, &index);
-	if (segment_seek(SEG, n, index) < 0) {
+	SEG->segment_address(SEG, row, col, &n, &index);
+	if (SEG->segment_seek(SEG, n, index) < 0) {
 	    G_warning
 		("Failed seek in segment file for index = %d n = %d at col:row %d:%d",
 		 index, n, col, row);
@@ -80,8 +80,8 @@
     }
 
     if ((size = SEG->spill * SEG->len)) {
-	segment_address(SEG, row, col, &n, &index);
-	if (segment_seek(SEG, n, index) < 0) {
+	SEG->segment_address(SEG, row, col, &n, &index);
+	if (SEG->segment_seek(SEG, n, index) < 0) {
 	    G_warning
 		("Failed seek in segment file for index = %d n = %d at col:row %d:%d",
 		 index, n, col, row);

Modified: grass/trunk/lib/segment/seek.c
===================================================================
--- grass/trunk/lib/segment/seek.c	2011-12-05 12:48:56 UTC (rev 49547)
+++ grass/trunk/lib/segment/seek.c	2011-12-05 12:49:48 UTC (rev 49548)
@@ -57,10 +57,7 @@
     return 0;
 }
 
-static int (*segment_seek_mode[2]) () = {
-segment_seek_fast, segment_seek_slow};
-
 int segment_seek(const SEGMENT * SEG, int n, int index)
 {
-    return (*segment_seek_mode[SEG->slow_seek]) (SEG, n, index);
+    return SEG->segment_seek(SEG, n, index);
 }

Modified: grass/trunk/lib/segment/setup.c
===================================================================
--- grass/trunk/lib/segment/setup.c	2011-12-05 12:48:56 UTC (rev 49547)
+++ grass/trunk/lib/segment/setup.c	2011-12-05 12:49:48 UTC (rev 49548)
@@ -71,9 +71,14 @@
 	    SEG->srowbits = seg_exp;
 	    SEG->segbits = SEG->srowbits + SEG->scolbits;
 	    SEG->slow_adrs = 0;
-	    G_debug(1, "segment lib: fast address activated");
+	    G_debug(1, "segment_setup: fast address activated");
 	}
     }
+    if (SEG->slow_adrs)
+	SEG->segment_address = segment_address_slow;
+    else
+	SEG->segment_address = segment_address_fast;
+    
     /* fast seek */
     SEG->slow_seek = 1;
     if (SEG->slow_adrs == 0) {
@@ -84,14 +89,18 @@
 	    SEG->lenbits = seg_exp;
 	    SEG->sizebits = SEG->segbits + SEG->lenbits;
 	    SEG->slow_seek = 0;
-	    G_debug(1, "segment lib: fast seek activated");
+	    G_debug(1, "segment_setup: fast seek activated");
 	}
     }
+    if (SEG->slow_seek)
+	SEG->segment_seek = segment_seek_slow;
+    else
+	SEG->segment_seek = segment_seek_fast;
 
     /* adjust number of open segments if larger than number of total segments */
     n_total_segs = SEG->spr * ((SEG->nrows + SEG->srows - 1) / SEG->srows);
     if (SEG->nseg > n_total_segs) {
-	G_debug(1, "segment: reducing number of open segments from %d to %d",
+	G_debug(1, "segment_setup: reducing number of open segments from %d to %d",
 		  SEG->nseg, n_total_segs);
 	SEG->nseg = n_total_segs;
     }



More information about the grass-commit mailing list