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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Mikel Astiz <mikel.astiz@xxxxxxxxxxxx>

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

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux