This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 0abde8309 log_fcb: optimize log_fcb_copy
0abde8309 is described below

commit 0abde83093aa879c18a43bdcbac4d4e048207543
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Fri Apr 25 15:42:28 2025 +0200

    log_fcb: optimize log_fcb_copy
    
    Local function log_fcb_copy() did not use information
    about start location that was already available.
    Function log_fcb_rtr_erase() found first element to
    copy and then used only part of what wa returned.
    In turn log_fcb_copy() walk log again skipping
    entries.
    
    It would not work correctly if more then on sector
    was used for source fcb and requested number of
    preserved entries span more then one sector.
    
    Signed-off-by: Jerzy Kasenberg <[email protected]>
---
 sys/log/full/src/log_fcb.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index 48bcfc329..bc43babc3 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -960,24 +960,19 @@ err:
  * @param log      Log this operation applies to
  * @param src_fcb  FCB area which is the source of data
  * @param dst_fcb  FCB area which is the target
- * @param offset   Flash offset where to start the copy
+ * @param entry    Location in src_fcb to start copy from
  *
  * @return 0 on success; non-zero on error
  */
 static int
 log_fcb_copy(struct log *log, struct fcb *src_fcb, struct fcb *dst_fcb,
-             uint32_t offset)
+             struct fcb_entry *entry)
 {
-    struct fcb_entry entry;
     int rc;
 
     rc = 0;
-    memset(&entry, 0, sizeof(entry));
-    while (!fcb_getnext(src_fcb, &entry)) {
-        if (entry.fe_elem_off < offset) {
-            continue;
-        }
-        rc = log_fcb_copy_entry(log, &entry, dst_fcb);
+    while (!fcb_getnext(src_fcb, entry)) {
+        rc = log_fcb_copy_entry(log, entry, dst_fcb);
         if (rc) {
             break;
         }
@@ -1038,7 +1033,7 @@ log_fcb_rtr_erase(struct log *log)
     }
 
     /* Copy to scratch */
-    rc = log_fcb_copy(log, fcb, &fcb_scratch, entry.fe_elem_off);
+    rc = log_fcb_copy(log, fcb, &fcb_scratch, &entry);
     if (rc) {
         goto err;
     }
@@ -1049,8 +1044,9 @@ log_fcb_rtr_erase(struct log *log)
         goto err;
     }
 
+    memset(&entry, 0, sizeof(entry));
     /* Copy back from scratch */
-    rc = log_fcb_copy(log, &fcb_scratch, fcb, 0);
+    rc = log_fcb_copy(log, &fcb_scratch, fcb, &entry);
 
 err:
     return (rc);

Reply via email to