From nobody Mon Oct 28 21:43:01 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Xcn1d4Bbwz5bpym; Mon, 28 Oct 2024 21:43:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xcn1d1km0z4mJX; Mon, 28 Oct 2024 21:43:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730151781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZyK7CXT6kyn7eO3N27skHtilIUPOfpZECJroIKTBdoc=; b=o+Jj6WbHhiTDYLlnUeWsLPN1Q7wsmR4yBuosctNPJDJWaNFS8xIoVO/ZqKU/6wQoRytm5C V3kr0zl6QN2hkkA1+7zhsEl4pjgyLXvx47hpAp12mP7/SUbWoWR1qEzyoLq5u6wsTQ9NBp FAifOwKIKfDX7pRrzHDrDB2JB6xX4dhLQQrDSieqWFV7edUONiDRxhyCgbyEySTHIxb920 Pn+yinCyS4V2b+tIvFcMwyGDgY1h+fOw8kjnDqHn0Jgokm29AMa12Q9T2fTKSsGHkInF1I 6HkLl50BIUXYSBwVq2SQOTmoMAe+alFjXILTW5N+xqNE89yGaC9S+viW+gQ1Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730151781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZyK7CXT6kyn7eO3N27skHtilIUPOfpZECJroIKTBdoc=; b=Eq6+guzK94Q8OruLqYYMyfHrZu+duRh9yAyRsblM8L9+yPkdNKxGzazvP27q71jIPUCnLh w6rK4lvT+boQUjxXYgwP5F0Fw/EMl/5A3IR8BQFl/0LrKRFYm1aqr3bHxs1/SrMExo3w3s CQeQqXEQ+NZzmuaZdzlrYNk3LlToLf4iKOJ89df+pDOPYItdVDiLgU/SA6ijnLEzfwW2Fx nU/RwIwDemT6UNz1tzeite0dz3ctnDLh0Yj4l5v9fnbMr6Lg1dWg6H5rIUMQ5Ebypv8gKl kizUHb0ZucOEF9zpnjnC8SVDZ863DNXOaosto16ix19KH42tQfveHr1Ky69a2A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730151781; a=rsa-sha256; cv=none; b=A1e7+7CFeaJ873JjgYEbdVjgJyaDOUOnv7myB+zOekB9ju4uNlfV5+ObSflcL7QmrE2r3n 1bfPxwNrSMnL0jXfN+CIgdkQyV8WkntQDLc3/TMGQwY7xLIFCPMykw//5r8qoRnymGwUQ/ mNl6lTDi5P9wGhxrL1zHdxkJCnbGiRHNGud6tlcEZy/hxviMLjvwqz4lcv8E/SqKz5u4pO b+gnE93iiC1FZg/3akRe4SBI026bwDRgIgs3sOgzSpiCyjk0ZBMwR3Gq+zPIGZ4nQGty1l 0iadU0BMS5Kopf5Nm1CvecvFiQG525BdDTCT3dWDHPkHaC4IeSx3SvM4EU8cyQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Xcn1d1Ljjzwg6; Mon, 28 Oct 2024 21:43:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49SLh1oc074878; Mon, 28 Oct 2024 21:43:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49SLh1IQ074875; Mon, 28 Oct 2024 21:43:01 GMT (envelope-from git) Date: Mon, 28 Oct 2024 21:43:01 GMT Message-Id: <202410282143.49SLh1IQ074875@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Moore Subject: git: b02d6a6b5a07 - main - pctrie: reduce code duplication in PCTRIE_INSERT_* List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dougm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b02d6a6b5a0753ea8be53d6bd6d4f39f046c54f4 Auto-Submitted: auto-generated The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=b02d6a6b5a0753ea8be53d6bd6d4f39f046c54f4 commit b02d6a6b5a0753ea8be53d6bd6d4f39f046c54f4 Author: Doug Moore AuthorDate: 2024-10-28 19:00:00 +0000 Commit: Doug Moore CommitDate: 2024-10-28 21:42:47 +0000 pctrie: reduce code duplication in PCTRIE_INSERT_* The four flavors of PCTRIE_INSERT inline functions share a few lines of code. Extract that code into a new function and invoke it from the others to reduce code duplication. No behavior change expected. Reviewed by: bnovkov Differential Revision: https://reviews.freebsd.org/D47288 --- sys/sys/pctrie.h | 85 +++++++++++++++++++++++++------------------------------- 1 file changed, 38 insertions(+), 47 deletions(-) diff --git a/sys/sys/pctrie.h b/sys/sys/pctrie.h index 209380d805b2..54b7fb401202 100644 --- a/sys/sys/pctrie.h +++ b/sys/sys/pctrie.h @@ -86,69 +86,67 @@ name##_PCTRIE_PTR2VAL(struct type *ptr) \ } \ \ static __inline __unused int \ -name##_PCTRIE_INSERT(struct pctrie *ptree, struct type *ptr) \ +name##_PCTRIE_INSERT_BASE(struct pctrie *ptree, void *parentp, \ + uint64_t *val, uint64_t *found, struct type **found_out) \ { \ struct pctrie_node *parent; \ + \ + if (__predict_false(found != NULL)) { \ + *found_out = name##_PCTRIE_VAL2PTR(found); \ + return (EEXIST); \ + } \ + if (parentp != NULL) { \ + parent = allocfn(ptree); \ + if (__predict_false(parent == NULL)) { \ + if (found_out != NULL) \ + *found_out = NULL; \ + return (ENOMEM); \ + } \ + pctrie_insert_node(parentp, parent, val); \ + } \ + return (0); \ +} \ + \ +static __inline __unused int \ +name##_PCTRIE_INSERT(struct pctrie *ptree, struct type *ptr) \ +{ \ void *parentp; \ uint64_t *val = name##_PCTRIE_PTR2VAL(ptr); \ \ parentp = pctrie_insert_lookup_strict(ptree, val); \ - if (parentp == NULL) \ - return (0); \ - parent = allocfn(ptree); \ - if (__predict_false(parent == NULL)) \ - return (ENOMEM); \ - pctrie_insert_node(parentp, parent, val); \ - return (0); \ + return (name##_PCTRIE_INSERT_BASE(ptree, parentp, val, \ + NULL, NULL)); \ } \ \ static __inline __unused int \ name##_PCTRIE_FIND_OR_INSERT(struct pctrie *ptree, struct type *ptr, \ struct type **found_out_opt) \ { \ - struct pctrie_node *parent; \ void *parentp; \ uint64_t *val = name##_PCTRIE_PTR2VAL(ptr); \ uint64_t *found; \ \ parentp = pctrie_insert_lookup(ptree, val, &found); \ - if (found != NULL) { \ - if (found_out_opt != NULL) \ - *found_out_opt = name##_PCTRIE_VAL2PTR(found); \ - return (EEXIST); \ - } \ - if (parentp == NULL) \ - return (0); \ - parent = allocfn(ptree); \ - if (__predict_false(parent == NULL)) \ - return (ENOMEM); \ - pctrie_insert_node(parentp, parent, val); \ - return (0); \ + return (name##_PCTRIE_INSERT_BASE(ptree, parentp, val, \ + found, found_out_opt)); \ } \ \ static __inline __unused int \ name##_PCTRIE_INSERT_LOOKUP_GE(struct pctrie *ptree, struct type *ptr, \ struct type **found_out) \ { \ - struct pctrie_node *parent, *neighbor; \ + struct pctrie_node *neighbor; \ void *parentp; \ uint64_t *val = name##_PCTRIE_PTR2VAL(ptr); \ uint64_t *found; \ + int retval; \ \ parentp = pctrie_insert_lookup_gt(ptree, val, &found, \ &neighbor); \ - if (__predict_false(found != NULL)) { \ - *found_out = name##_PCTRIE_VAL2PTR(found); \ - return (EEXIST); \ - } \ - if (parentp != NULL) { \ - parent = allocfn(ptree); \ - if (__predict_false(parent == NULL)) { \ - *found_out = NULL; \ - return (ENOMEM); \ - } \ - pctrie_insert_node(parentp, parent, val); \ - } \ + retval = name##_PCTRIE_INSERT_BASE(ptree, parentp, val, \ + found, found_out); \ + if (retval != 0) \ + return (retval); \ found = pctrie_subtree_lookup_gt(neighbor, *val); \ *found_out = name##_PCTRIE_VAL2PTR(found); \ pctrie_subtree_lookup_gt_assert(neighbor, *val, ptree, found); \ @@ -159,25 +157,18 @@ static __inline __unused int \ name##_PCTRIE_INSERT_LOOKUP_LE(struct pctrie *ptree, struct type *ptr, \ struct type **found_out) \ { \ - struct pctrie_node *parent, *neighbor; \ + struct pctrie_node *neighbor; \ void *parentp; \ uint64_t *val = name##_PCTRIE_PTR2VAL(ptr); \ uint64_t *found; \ + int retval; \ \ parentp = pctrie_insert_lookup_lt(ptree, val, &found, \ &neighbor); \ - if (__predict_false(found != NULL)) { \ - *found_out = name##_PCTRIE_VAL2PTR(found); \ - return (EEXIST); \ - } \ - if (parentp != NULL) { \ - parent = allocfn(ptree); \ - if (__predict_false(parent == NULL)) { \ - *found_out = NULL; \ - return (ENOMEM); \ - } \ - pctrie_insert_node(parentp, parent, val); \ - } \ + retval = name##_PCTRIE_INSERT_BASE(ptree, parentp, val, \ + found, found_out); \ + if (retval != 0) \ + return (retval); \ found = pctrie_subtree_lookup_lt(neighbor, *val); \ *found_out = name##_PCTRIE_VAL2PTR(found); \ pctrie_subtree_lookup_lt_assert(neighbor, *val, ptree, found); \