[postgis-tickets] r16136 - Minor efficiency changes in bytebuffer, stricter function

Paul Ramsey pramsey at cleverelephant.ca
Thu Dec 7 13:46:47 PST 2017


Author: pramsey
Date: 2017-12-07 13:46:47 -0800 (Thu, 07 Dec 2017)
New Revision: 16136

Modified:
   trunk/liblwgeom/bytebuffer.c
   trunk/liblwgeom/liblwgeom.h.in
   trunk/liblwgeom/lwout_twkb.c
   trunk/liblwgeom/lwout_wkb.c
Log:
Minor efficiency changes in bytebuffer, stricter function 
signature for hexbytes, slight re-order of ops in twkb.


Modified: trunk/liblwgeom/bytebuffer.c
===================================================================
--- trunk/liblwgeom/bytebuffer.c	2017-12-06 20:00:21 UTC (rev 16135)
+++ trunk/liblwgeom/bytebuffer.c	2017-12-07 21:46:47 UTC (rev 16136)
@@ -141,7 +141,6 @@
 {
 	LWDEBUGF(2,"Entered bytebuffer_makeroom with space need of %d", size_to_add);
 	size_t current_write_size = (s->writecursor - s->buf_start);
-	size_t current_read_size = (s->readcursor - s->buf_start);
 	size_t capacity = s->capacity;
 	size_t required_size = current_write_size + size_to_add;
 
@@ -151,6 +150,7 @@
 
 	if ( capacity > s->capacity )
 	{
+		size_t current_read_size = (s->readcursor - s->buf_start);
 		LWDEBUGF(4,"We need to realloc more memory. New capacity is %d", capacity);
 		if ( s->buf_start == s->buf_static )
 		{
@@ -238,10 +238,8 @@
 void
 bytebuffer_append_varint(bytebuffer_t *b, const int64_t val)
 {
-	size_t size;
 	bytebuffer_makeroom(b, 16);
-	size = varint_s64_encode_buf(val, b->writecursor);
-	b->writecursor += size;
+	b->writecursor += varint_s64_encode_buf(val, b->writecursor);
 	return;
 }
 
@@ -251,10 +249,8 @@
 void
 bytebuffer_append_uvarint(bytebuffer_t *b, const uint64_t val)
 {
-	size_t size;
 	bytebuffer_makeroom(b, 16);
-	size = varint_u64_encode_buf(val, b->writecursor);
-	b->writecursor += size;
+	b->writecursor += varint_u64_encode_buf(val, b->writecursor);
 	return;
 }
 

Modified: trunk/liblwgeom/liblwgeom.h.in
===================================================================
--- trunk/liblwgeom/liblwgeom.h.in	2017-12-06 20:00:21 UTC (rev 16135)
+++ trunk/liblwgeom/liblwgeom.h.in	2017-12-07 21:46:47 UTC (rev 16136)
@@ -2125,7 +2125,7 @@
 
 extern uint8_t*  bytes_from_hexbytes(const char *hexbuf, size_t hexsize);
 
-extern char*   hexbytes_from_bytes(uint8_t *bytes, size_t size);
+extern char*   hexbytes_from_bytes(const uint8_t *bytes, size_t size);
 
 /*
 * WKT detailed parsing support

Modified: trunk/liblwgeom/lwout_twkb.c
===================================================================
--- trunk/liblwgeom/lwout_twkb.c	2017-12-06 20:00:21 UTC (rev 16135)
+++ trunk/liblwgeom/lwout_twkb.c	2017-12-07 21:46:47 UTC (rev 16136)
@@ -406,7 +406,7 @@
 
 static int lwgeom_write_to_buffer(const LWGEOM *geom, TWKB_GLOBALS *globals, TWKB_STATE *parent_state)
 {
-	int i, is_empty, has_z, has_m, ndims;
+	int i, is_empty, has_z = 0, has_m = 0, ndims;
 	size_t bbox_size = 0, optional_precision_byte = 0;
 	uint8_t flag = 0, type_prec = 0;
 	bytebuffer_t header_bytebuffer, geom_bytebuffer;
@@ -421,10 +421,13 @@
 	bytebuffer_init_with_size(child_state.geom_buf, 64);
 
 	/* Read dimensionality from input */
-	has_z = lwgeom_has_z(geom);
-	has_m = lwgeom_has_m(geom);
 	ndims = lwgeom_ndims(geom);
 	is_empty = lwgeom_is_empty(geom);
+	if ( ndims > 2 )
+	{
+		has_z = lwgeom_has_z(geom);
+		has_m = lwgeom_has_m(geom);
+	}
 
 	/* Do we need extended precision? If we have a Z or M we do. */
 	optional_precision_byte = (has_z || has_m);

Modified: trunk/liblwgeom/lwout_wkb.c
===================================================================
--- trunk/liblwgeom/lwout_wkb.c	2017-12-06 20:00:21 UTC (rev 16135)
+++ trunk/liblwgeom/lwout_wkb.c	2017-12-07 21:46:47 UTC (rev 16136)
@@ -36,7 +36,7 @@
 */
 static char *hexchr = "0123456789ABCDEF";
 
-char* hexbytes_from_bytes(uint8_t *bytes, size_t size)
+char* hexbytes_from_bytes(const uint8_t *bytes, size_t size)
 {
 	char *hex;
 	int i;



More information about the postgis-tickets mailing list