[GRASS-SVN] r71937 - grass-addons/grass7/raster/r.resamp.tps
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Dec 14 06:26:47 PST 2017
Author: mmetz
Date: 2017-12-14 06:26:47 -0800 (Thu, 14 Dec 2017)
New Revision: 71937
Modified:
grass-addons/grass7/raster/r.resamp.tps/cache.c
grass-addons/grass7/raster/r.resamp.tps/cache.h
Log:
r.resamp.tps: improve cache
Modified: grass-addons/grass7/raster/r.resamp.tps/cache.c
===================================================================
--- grass-addons/grass7/raster/r.resamp.tps/cache.c 2017-12-14 14:25:58 UTC (rev 71936)
+++ grass-addons/grass7/raster/r.resamp.tps/cache.c 2017-12-14 14:26:47 UTC (rev 71937)
@@ -6,12 +6,12 @@
static void *cache_get_r(struct cache *c, void *p, int row, int col)
{
- return memcpy(p, c->r[row][col], c->n);
+ return memcpy(p, c->r + ((size_t)row * c->cols + col) * c->n, c->n);
}
static void *cache_put_r(struct cache *c, void *p, int row, int col)
{
- return memcpy(c->r[row][col], p, c->n);
+ return memcpy(c->r + ((size_t)row * c->cols + col) * c->n, p, c->n);
}
static void *cache_get_s(struct cache *c, void *p, int row, int col)
@@ -47,25 +47,9 @@
c->put = cache_put_s;
}
else {
- int row, col;
-
G_verbose_message("Using memory cache");
- c->r = G_malloc(sizeof(char **) * c->rows);
- row = 0;
- c->r[row] = G_malloc(sizeof(char *) * c->rows * c->cols);
- c->r[row][0] = G_malloc(sizeof(char) * c->rows * c->cols * c->n);
- for (col = 1; col < c->cols; col++) {
- c->r[row][col] = c->r[row][col - 1] + c->n;
- }
- for (row = 1; row < c->rows; row++) {
- c->r[row] = c->r[row - 1] + c->cols;
- c->r[row][0] = c->r[row - 1][0] + c->cols * c->n;
- for (col = 1; col < c->cols; col++) {
- c->r[row][col] = c->r[row][col - 1] + c->n;
- }
- }
-
+ c->r = G_malloc(sizeof(char) * c->rows * c->cols * c->n);
c->get = cache_get_r;
c->put = cache_put_r;
}
@@ -79,8 +63,6 @@
Segment_close(&c->s);
}
else {
- G_free(c->r[0][0]);
- G_free(c->r[0]);
G_free(c->r);
}
Modified: grass-addons/grass7/raster/r.resamp.tps/cache.h
===================================================================
--- grass-addons/grass7/raster/r.resamp.tps/cache.h 2017-12-14 14:25:58 UTC (rev 71936)
+++ grass-addons/grass7/raster/r.resamp.tps/cache.h 2017-12-14 14:26:47 UTC (rev 71937)
@@ -3,7 +3,7 @@
struct cache
{
SEGMENT s;
- char ***r;
+ char *r;
int n; /* data size per cell in bytes */
int rows, cols;
void *(* get)(struct cache *c, void *p, int row, int col);
More information about the grass-commit
mailing list