[GRASS-SVN] r36024 - in grass/branches/develbranch_6: include
lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Feb 22 03:54:28 EST 2009
Author: hamish
Date: 2009-02-22 03:54:28 -0500 (Sun, 22 Feb 2009)
New Revision: 36024
Modified:
grass/branches/develbranch_6/include/gisdefs.h
grass/branches/develbranch_6/lib/gis/gisinit.c
grass/branches/develbranch_6/lib/gis/null_val.c
Log:
backport faster null check for G_is_c_null_value() (trac #392)
Modified: grass/branches/develbranch_6/include/gisdefs.h
===================================================================
--- grass/branches/develbranch_6/include/gisdefs.h 2009-02-22 06:20:49 UTC (rev 36023)
+++ grass/branches/develbranch_6/include/gisdefs.h 2009-02-22 08:54:28 UTC (rev 36024)
@@ -837,7 +837,6 @@
char *G_fully_qualified_name(const char *, const char *);
/* null_val.c */
-void G__init_null_patterns(void);
void G__set_null_value(void *, int, int, RASTER_MAP_TYPE);
void G_set_null_value(void *, int, RASTER_MAP_TYPE);
void G_set_c_null_value(CELL *, int);
Modified: grass/branches/develbranch_6/lib/gis/gisinit.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/gisinit.c 2009-02-22 06:20:49 UTC (rev 36023)
+++ grass/branches/develbranch_6/lib/gis/gisinit.c 2009-02-22 08:54:28 UTC (rev 36024)
@@ -135,9 +135,6 @@
/* Set masking flag unknown */
G__.auto_mask = -1;
- /* set architecture dependent bit patterns for embeded null vals */
- G__init_null_patterns();
-
initialized = 1;
setlocale(LC_NUMERIC, "C");
Modified: grass/branches/develbranch_6/lib/gis/null_val.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/null_val.c 2009-02-22 06:20:49 UTC (rev 36023)
+++ grass/branches/develbranch_6/lib/gis/null_val.c 2009-02-22 08:54:28 UTC (rev 36024)
@@ -24,31 +24,8 @@
#include <grass/gis.h>
#include <grass/glocale.h>
-/*======================= Internal Constants/Defines =======================*/
-
-/* none */
-
-/*========================== Internal Typedefs =============================*/
-
-/* none */
-
-/*====================== Static Variable Declaration =======================*/
-
-/* Null pattern variables */
-static CELL cellNullPattern;
-static FCELL fcellNullPattern;
-static DCELL dcellNullPattern;
-
-/* Flag to indicate null patterns are initialized */
-static int initialized = FALSE;
-
-/*============================== Prototypes ================================*/
-
static int EmbedGivenNulls(void *, char *, RASTER_MAP_TYPE, int);
-static void InitError(void);
-/*======================= Internal Static Functions ========================*/
-
/****************************************************************************
* int EmbedGivenNulls (void *cell, char *nulls, RASTER_MAP_TYPE map_type,
* int ncols)
@@ -96,81 +73,9 @@
return 1;
}
-/****************************************************************************
-* void InitError (void)
-*
-* PURPOSE: To print an error message and exit the program. This function
-* is called if something tries to access a null pattern before
-* it is initialized.
-* INPUT VARS: none
-* RETURN VAL: none
-*****************************************************************************/
-static void InitError(void)
-{
- char errMsg[512]; /* array to hold error message */
-
- strcpy(errMsg, _("Null values have not been initialized. "));
- strcat(errMsg, _("G_gisinit() must be called first. "));
- strcat(errMsg, _("Please advise GRASS developers of this error.\n"));
- G_fatal_error(errMsg);
-
- return;
-}
-
/*========================== Library Functions =============================*/
/****************************************************************************
-* void G__init_null_patterns (void)
-*
-* PURPOSE: To initialize the three null patterns for CELL, FCELL, and
-* DCELL data types. It also sets the initialized flag to TRUE.
-* This function is called by G_gisinit()
-* INPUT VARS: none
-* RETURN VAL: none
-*****************************************************************************/
-void G__init_null_patterns(void)
-{
- unsigned char *bytePtr; /* pointer to traverse FCELL and DCELL */
- int numBits; /* number of bits for CELL type */
- int i; /* counter */
-
- if (!initialized) {
- /* Create the null pattern for the CELL data type - set the left */
- /* most bit to 1 and the rest to 0, basically INT_MIN. Since CELL is */
- /* some type of integer the bytes are not split into exponent and */
- /* mantissa. Thus a simple left shift can be used */
- numBits = sizeof(CELL) * 8;
-
- cellNullPattern = 1 << (numBits - 1);
-
- /* Create the null pattern for the FCELL data type - set all bits */
- /* to 1, basically NaN. Need to use a byte pointer since bytes */
- /* represent the exponent and mantissa */
- bytePtr = (unsigned char *)&fcellNullPattern;
-
- for (i = 0; i < sizeof(FCELL); i++) {
- *bytePtr = (unsigned char)255;
- bytePtr++;
- }
-
- /* Create the null pattern for the DCELL data type - set all bits */
- /* to 1, basically NaN. Need to use a byte pointer since bytes */
- /* represent the exponent and mantissa */
- bytePtr = (unsigned char *)&dcellNullPattern;
-
- for (i = 0; i < sizeof(DCELL); i++) {
- *bytePtr = (unsigned char)255;
- bytePtr++;
- }
-
- /* Set the initialized flag to TRUE */
- initialized = TRUE;
- }
-
- return;
-}
-
-/****************************************************************************
* void G__set_null_value (void *rast, int numVals, int null_is_zero,
* RASTER_MAP_TYPE data_type)
*
@@ -234,25 +139,12 @@
* numVals => number of values to set to null
* RETURN VAL: none
*****************************************************************************/
-void G_set_c_null_value(CELL * cellVals, int numVals)
+void G_set_c_null_value(CELL *cellVals, int numVals)
{
- CELL *cellPtr; /* pointer to CELL array to set to null */
int i; /* counter */
- /* Check if the null patterns have been initialized */
- if (!initialized) {
- InitError();
- }
-
- /* Set numVals consecutive CELL values to null */
- cellPtr = cellVals;
-
- for (i = 0; i < numVals; i++) {
- *cellPtr = cellNullPattern;
- cellPtr++;
- }
-
- return;
+ for (i = 0; i < numVals; i++)
+ cellVals[i] = (int) 0x80000000;
}
/****************************************************************************
@@ -263,25 +155,14 @@
* numVals => number of values to set to null
* RETURN VAL: none
*****************************************************************************/
-void G_set_f_null_value(FCELL * fcellVals, int numVals)
+void G_set_f_null_value(FCELL *fcellVals, int numVals)
{
- FCELL *fcellPtr; /* pointer to FCELL array to set to null */
- int i; /* counter */
+ static const unsigned char null_bits[4] = {
+ 0xFF, 0xFF, 0xFF, 0xFF};
+ int i;
- /* Check if the null patterns have been initialized */
- if (!initialized) {
- InitError();
- }
-
- /* Set numVals consecutive FCELL values to null */
- fcellPtr = fcellVals;
-
- for (i = 0; i < numVals; i++) {
- *fcellPtr = fcellNullPattern;
- fcellPtr++;
- }
-
- return;
+ for (i = 0; i < numVals; i++)
+ memcpy(&fcellVals[i], null_bits, sizeof(null_bits));
}
/****************************************************************************
@@ -292,25 +173,14 @@
* numVals => number of values to set to null
* RETURN VAL: none
*****************************************************************************/
-void G_set_d_null_value(DCELL * dcellVals, int numVals)
+void G_set_d_null_value(DCELL *dcellVals, int numVals)
{
- DCELL *dcellPtr; /* pointer to DCELL array to set to null */
- int i; /* counter */
+ static const unsigned char null_bits[8] = {
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+ int i;
- /* Check if the null patterns have been initialized */
- if (!initialized) {
- InitError();
- }
-
- /* Set numVals consecutive DCELL values to null */
- dcellPtr = dcellVals;
-
- for (i = 0; i < numVals; i++) {
- *dcellPtr = dcellNullPattern;
- dcellPtr++;
- }
-
- return;
+ for (i = 0; i < numVals; i++)
+ memcpy(&dcellVals[i], null_bits, sizeof(null_bits));
}
/****************************************************************************
@@ -373,22 +243,8 @@
int G_is_c_null_value(const CELL * cellVal)
{
- int i; /* counter */
-
- /* Check if the null patterns have been initialized */
- if (!initialized) {
- InitError();
- }
-
/* Check if the CELL value matches the null pattern */
- for (i = 0; i < sizeof(CELL); i++) {
- if (((unsigned char *)cellVal)[i] !=
- ((unsigned char *)&cellNullPattern)[i]) {
- return FALSE;
- }
- }
-
- return TRUE;
+ return *cellVal == (CELL) 0x80000000;
}
/****************************************************************************
More information about the grass-commit
mailing list