Patchwork [v2,15/15] qcow2: small optimization

login
register
mail settings
Submitter Frediano Ziglio
Date Aug. 9, 2011, 7:46 a.m.
Message ID <1312876010-15361-16-git-send-email-freddy77@gmail.com>
Download mbox | patch
Permalink /patch/109164/
State New
Headers show

Comments

Frediano Ziglio - Aug. 9, 2011, 7:46 a.m.
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
---
 block/qcow2-refcount.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

Patch

diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 0e31868..318d66d 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -681,14 +681,13 @@  void qcow2_create_refcount_update(QCowCreateState *s, int64_t offset,
     int64_t size)
 {
     int refcount;
-    int64_t start, last, cluster_offset;
+    int64_t start, last, cluster;
     uint16_t *p;
 
-    start = offset & ~(s->cluster_size - 1);
-    last = (offset + size - 1)  & ~(s->cluster_size - 1);
-    for(cluster_offset = start; cluster_offset <= last;
-        cluster_offset += s->cluster_size) {
-        p = &s->refcount_block[cluster_offset >> s->cluster_bits];
+    start = offset >> s->cluster_bits;
+    last = (offset + size - 1)  >> s->cluster_bits;
+    for (cluster = start; cluster <= last; ++cluster) {
+        p = &s->refcount_block[cluster];
         refcount = be16_to_cpu(*p);
         refcount++;
         *p = cpu_to_be16(refcount);