From patchwork Sun Oct 13 12:49:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 11187387 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 73F44112B for ; Sun, 13 Oct 2019 12:49:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 491AF206A3 for ; Sun, 13 Oct 2019 12:49:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=web.de header.i=@web.de header.b="LRidhVIX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728789AbfJMMts (ORCPT ); Sun, 13 Oct 2019 08:49:48 -0400 Received: from mout.web.de ([212.227.17.12]:35373 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728159AbfJMMts (ORCPT ); Sun, 13 Oct 2019 08:49:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1570970982; bh=XZpFvCIqU/OBVgzBjG43dg2+NDTEoNXcdC3C1l5uXHQ=; h=X-UI-Sender-Class:To:Cc:From:Subject:Date; b=LRidhVIXoFaaHGTICzlpK1r1Y/ejt+4zZfosSvNa8h79Mhj7J9ApB1MGBQXKX9AEY yqthRSQtDBKprPt1Eb6ePMYK8we4ra2RObM1npVfW/Ozrabjg2L+rF73Sk9ShWtFd/ qIR8CcyyuaYC03Urbsl+4R6qG34YqQIfcKtGjLX4= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.26] ([91.47.146.29]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MSaZk-1iTdB43GPk-00RVzD; Sun, 13 Oct 2019 14:49:42 +0200 To: Git Mailing List Cc: Junio C Hamano From: =?utf-8?q?Ren=C3=A9_Scharfe?= Subject: [PATCH] http-push: simplify deleting a list item Message-ID: <3739b392-ee45-98c2-c5fa-e4c36e585166@web.de> Date: Sun, 13 Oct 2019 14:49:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 Content-Language: en-US X-Provags-ID: V03:K1:0sLogKY5CarveVwwiIsE6cFIXM/FQ/HPBDOuJAnni5ZccFKylKi SMAQujqyaqG15davOpa5MnDKftIFoq23Wbsm9PjXk8rnvDFvJvOkN+vg0t0tyBTY/4DZras mggeNoMHpeQU330O6fBJjsakINfG5/ZnNhXW2Mt2UN07vaSr8IZJ+TmXR/Ai38+x/uGLP+V K5ZoyumNztueCejPR5kwg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:gL8wu/df+6g=:q1rlDTWKH1x6oanHPNilUP G6G04DJtsoBOILIi8c3oYx6+VkJQPVujBZIheFj2A3jOBTw8ie1MSnh2H+IgJw++BnTmA/cxw KsopJQvLPxmWZ1kxndz83jWxzK5e9bjBWje/zDjVuenNOg1wXsq8xk7yWbVsuSt+u+y6E9K2Q yu4cy6TZWDffQHKg5wjeoYvJbAExvCiUom4E7sU202bkRBEOasNehS7Ah/zE6wgD7dL5Yt0ie Hzrq+cpSqU93xqFvyAiOq79yGG25tZnkvjmcr43Cru2/aaVz2whMOpPXHFgCGx0D2jY6BiH3D /YCrnQuEimaq4nqxaHUF+5wxmrLLrvAuLo9MLIUwSjPa7pVyX+PrQhzefBNuY6wUqiGszvuoD vNbF+1+vZzvJAlUqeA8xPM0/jXCG/fdpBh+cTX9f2eb6n+ZvW0PoeC8b2ydgWe5cOPKpF//i5 oo04tfTFgHpP6LNwUVh0u3v5SHpiRYAR19sinG+oZIC6X3P0DwcwSbmadkyD/6VWfVXx1fwUG lHkA54V+I6I6TjxV4tQNolAuW/qSdgdvOHwK28+R0EwnUJQIFXMhCyeGP/7qa7vE7VZJx7j7Z PzwUrTOkHPUhcVbrlClArSXTjLfxdzZVpEBeC0QtWbldR7dZ5oVH9BT/Mwg7203vu2N0u5O6z G9GS7srs85vd/fEj5QlVjWRVNp60+UTFnvK/fEzd4gayeZfC6xpBBrr0oa3vo2H5/ryt0HCg+ wPCD26bnIOVZV6BzqWJ+wESMdC/NmGlfPOzEphAEDqhu0kMvvLd4SR2NjV0LrqPc8NjwnjBre pi17xZnubG+qY9hi4uLkOO7DQOgm4ndf9ZIt28IKDQYysZlLsYE3XiN/sj8lxj7lgxf+fxOX0 Ry1KDTi6dZrF4b8EgQPfLJx/N+yw0r+BblxDoZTnsC4JEk061GBrNYM26r02JTrNzt7tlnLCa yg+h0vT+2e1NUB0OS6w3Iv5fda99vT+iYBVz3FXqfrMVNKPllH4cHKsxqx3xC7RrL9sFWXXxe fCfAJ+sKcooTFkZL5ogRW2n9uM/Is67iVc7QkuN6Wnv8PGQidbHiScBwjeKIG2lAcWll2+mab uw9kJSngnF3nzkN1WCkRzX6r8Z9TMVQ4nWcVngzRWMTVmgY5bU1eBwfyl/2P2fBUvN6ENIaqo 4c7SoZuuW3mzZIaX/N9RGivWMv+vmWO5DfnWfjG9EiUtQKmHaDt+BTSfCbZSia28AiyasO6Cs HKIY3M7uwn274AdYf/RNCrRmIzboYrfMt1Nugkg== Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The first step for deleting an item from a linked list is to locate the item preceding it. Be more careful in release_request() and handle an empty list. This only has consequences for invalid delete requests (removing the same item twice, or deleting an item that was never added to the list), but simplifies the loop condition as well as the check after the loop. Once we found the item's predecessor in the list, update its next pointer to skip over the item, which removes it from the list. In other words: Make the item's successor the successor of its predecessor. (At this point entry->next == request and prev->next == lock, respectively.) This is a bit simpler and saves a pointer dereference. Signed-off-by: René Scharfe --- http-push.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 2.23.0 diff --git a/http-push.c b/http-push.c index 0353f9f514..822f326599 100644 --- a/http-push.c +++ b/http-push.c @@ -501,10 +501,10 @@ static void release_request(struct transfer_request *request) if (request == request_queue_head) { request_queue_head = request->next; } else { - while (entry->next != NULL && entry->next != request) + while (entry && entry->next != request) entry = entry->next; - if (entry->next == request) - entry->next = entry->next->next; + if (entry) + entry->next = request->next; } free(request->url); @@ -981,7 +981,7 @@ static int unlock_remote(struct remote_lock *lock) while (prev && prev->next != lock) prev = prev->next; if (prev) - prev->next = prev->next->next; + prev->next = lock->next; } free(lock->owner);