Optimize virtio_enqueue_trim() a bit by nuking unneeded
authorkrw <krw@openbsd.org>
Wed, 31 May 2017 08:10:24 +0000 (08:10 +0000)
committerkrw <krw@openbsd.org>
Wed, 31 May 2017 08:10:24 +0000 (08:10 +0000)
re-initializations of statically set fields. Move a common
chunk out of both clauses of if/else.

No intentional functional change.

ok sf@

sys/dev/pv/virtio.c

index 116e100..3107ee8 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: virtio.c,v 1.9 2017/05/30 19:28:09 sf Exp $   */
+/*     $OpenBSD: virtio.c,v 1.10 2017/05/31 08:10:24 krw Exp $ */
 /*     $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */
 
 /*
@@ -735,37 +735,27 @@ virtio_enqueue_trim(struct virtqueue *vq, int slot, int nsegs)
 {
        struct vq_entry *qe1 = &vq->vq_entries[slot];
        struct vring_desc *vd = &vq->vq_desc[0];
-       struct vq_entry *qe;
-       int i, s;
+       int i;
 
        if ((vd[slot].flags & VRING_DESC_F_INDIRECT) == 0) {
-               qe1->qe_indirect = 0;
-               qe1->qe_desc_base = vd;
                qe1->qe_next = qe1->qe_index;
-
                /*
                 * N.B.: the vq_entries are ASSUMED to be a contiguous
                 *       block with slot being the index to the first one.
                 */
-               s = slot;
-               for (i = 0; i < nsegs - 1; i++) {
-                       qe = &vq->vq_entries[s+1];
-                       vd[s].flags = VRING_DESC_F_NEXT;
-                       vd[s].next = qe->qe_index;
-                       s = qe->qe_index;
-               }
-               vd[s].flags = 0;
        } else {
+               qe1->qe_next = 0;
                vd = &vq->vq_desc[qe1->qe_index];
                vd->len = sizeof(struct vring_desc) * nsegs;
                vd = qe1->qe_desc_base;
-               for (i = 0; i < nsegs; i++) {
-                       vd[i].flags = VRING_DESC_F_NEXT;
-                       if (i == (nsegs - 1))
-                               vd[i].flags = 0;
-               }
-               qe1->qe_next = 0;
+               slot = 0;
+       }
+
+       for (i = 0; i < nsegs -1 ; i++) {
+               vd[slot].flags = VRING_DESC_F_NEXT;
+               slot++;
        }
+       vd[slot].flags = 0;
 }
 
 /*