Thread (22 messages) flat view 22 messages, 3 authors, 2012-03-19
STALE5287d

[PATCH obexd v0 11/11] client: double transfer buf size in each realloc

From: Mikel Astiz <hidden>
Date: 2012-03-12 13:32:45
Subsystem: the rest · Maintainer: Linus Torvalds

From: Mikel Astiz <redacted>

This provides linear time complexity instead of quadratic time, which
can be considerable for big transfers.

The obvious drawback is that more memory will be required.
---
 client/transfer.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/client/transfer.c b/client/transfer.c
index 3b82ae9..72c27de 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -541,16 +541,17 @@ static gboolean handle_get_body(struct obc_transfer *transfer, GObexPacket *rsp)
 		}
 	} else {
 		struct mem_location *location = transfer->mem_location;
-		gsize bsize;
+		gint64 req_size;
 
 		assert(location != NULL);
 
-		/* copy all buffered data */
-		bsize = location->buffer_len - transfer->transferred;
-
 		/* for convenience, leave space for final null character */
-		if (bsize < len + 1) {
-			location->buffer_len += len + 1 - bsize;
+		req_size = transfer->transferred + len + 1;
+
+		if (location->buffer_len < req_size) {
+			while (location->buffer_len < req_size)
+				location->buffer_len *= 2;
+
 			location->buffer = g_realloc(location->buffer,
 							location->buffer_len);
 		}
-- 
1.7.7.6
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help