]> git.sesse.net Git - bmusb/commitdiff
Simplify decode_packs() through some pointer arithmetic.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 17 Sep 2015 20:35:46 +0000 (22:35 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 17 Sep 2015 20:35:46 +0000 (22:35 +0200)
bmusb.cpp

index ac73432b2fc7816802c1f9e5b377074994622ada..926bfa10dc195571d98346098cb43c0707ba4999 100644 (file)
--- a/bmusb.cpp
+++ b/bmusb.cpp
@@ -287,23 +287,18 @@ void decode_packs(const libusb_transfer *xfr,
 //exit(5);
                }
 
-               const unsigned char *iso_start = xfr->buffer + offset;
-               for (unsigned iso_offset = 0; iso_offset < pack->actual_length; ) {  // Usually runs only one iteration.
-                       const unsigned char* start_next_frame = (const unsigned char *)memmem(iso_start + iso_offset, pack->actual_length - iso_offset, sync_pattern, sync_length);
+               const uint8_t *start = xfr->buffer + offset;
+               const uint8_t *limit = start + pack->actual_length;
+               while (start < limit) {  // Usually runs only one iteration.
+                       const unsigned char* start_next_frame = (const unsigned char *)memmem(start, limit - start, sync_pattern, sync_length);
                        if (start_next_frame == nullptr) {
                                // add the rest of the buffer
-                               const uint8_t *start = iso_start + iso_offset;
-                               const uint8_t *end = iso_start + pack->actual_length;
-                               add_to_frame(current_frame, frame_type_name, start, end);
+                               add_to_frame(current_frame, frame_type_name, start, limit);
                                break;
                        } else {
-                               const uint8_t *start = iso_start + iso_offset;
-                               const uint8_t *end = start_next_frame;
-                               add_to_frame(current_frame, frame_type_name, start, end);
-                               start_callback(start_next_frame + sync_length);
-
-                               int suboffset = start_next_frame - iso_start;
-                               iso_offset = suboffset + sync_length;  // skip sync
+                               add_to_frame(current_frame, frame_type_name, start, start_next_frame);
+                               start = start_next_frame + sync_length;  // skip sync
+                               start_callback(start);
                        }
                }
 #if 0