From patchwork Tue Sep 12 12:17:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 812815 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461910-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="tmegvd/h"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xs3j30Vh4z9s5L for ; Tue, 12 Sep 2017 22:17:57 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=d7ygFIKsmFRPJjM3VSqW9CzHs4w6psA45Fqj/TRvHaUPr5KFXn jG3scps04ZC8Irjn0smp1VMmSljYI40xUTDPilLA2sUxnTARVMU40srSpjtc/xWn Wp8t18irbIR9+yt2gkaXE+PRv7jQzTtvyL8hYOZpGqYZrvelWNN7LYOrc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=cptlAUCr2tVUF/jHOtIjrKE4X2U=; b=tmegvd/ht3ZfUfGa5+R8 lmqHuhjS31lnOpV+0cYsE2nYAkhzqW0Sna2wuXluzjqgXkUa8Wanolxv3C5SugPZ eDaSib1KuVvLI35HvZyekO11sj4icUvjdvf0TnoDlrdTnT32+e4s755LiLknHn2u h7eqN0XEBOohmDTvxTOQSto= Received: (qmail 1000 invoked by alias); 12 Sep 2017 12:17:50 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 984 invoked by uid 89); 12 Sep 2017 12:17:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=U*nathan, H*MI:5267, H*M:5267, Resort X-HELO: mail-yw0-f173.google.com Received: from mail-yw0-f173.google.com (HELO mail-yw0-f173.google.com) (209.85.161.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Sep 2017 12:17:47 +0000 Received: by mail-yw0-f173.google.com with SMTP id s62so27787461ywg.0 for ; Tue, 12 Sep 2017 05:17:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=4aKJlqpzkR47lxDzELnO2WS8fVLCCjBtneFMIVBIv/k=; b=UjWiC5xnhRp2Yi/gN1kTbkJkTtrEgB2g+KcW6b17hR66Ci7mK5SnFL145fDTksZ54S VRPjkHBuB7z+Us+5uBCnxpgwBCWqOtZtP+wiYet56PHEwLs30E6dze9oB0bw+4LqbvCJ bd9vxloZ46TdTY14x1rx5zZG2PqFxMJB0pAb7lL+xTspfZL3dfJWg32NN7Q6zD3CqMB/ oBjj3wtarWfzqOfeNy4lN9/rSWD1/PKqOVoRZg5Jz4S0kzaaXvPwFIaqLwmGWk57v3zX xKN8pVFaLawUq55EC7jlX2353GWGoacOgIxigm95V8AYMKoVrewcwRykzTQZZXYAuB7m 0vTA== X-Gm-Message-State: AHPjjUhqV4INyZ1pQ78DSDHH+UsXzwGEz1Bc9TGDmakxCb+Q9Li6mtH8 U4Cc8RnicKAOSA== X-Google-Smtp-Source: ADKCNb5jiXG5ndN6dc5Yc8mnX8CPvjcUghnl0WL8fF6r9dbeAYhKZ5YWMP8qLmiLsLqHkMA2EBwH0w== X-Received: by 10.37.22.70 with SMTP id 67mr12277837ybw.32.1505218665957; Tue, 12 Sep 2017 05:17:45 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::a68b]) by smtp.googlemail.com with ESMTPSA id x4sm3740936ywa.58.2017.09.12.05.17.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Sep 2017 05:17:45 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] small METHOD_VEC cleanup Message-ID: <0bbbc933-257c-77eb-5267-237f403758ea@acm.org> Date: Tue, 12 Sep 2017 08:17:43 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 It turned out I wasn't quite at the point of committing my sorted_fields killing patch. This one just cleans up some functions affected by that, and I've applied it separately to reduce the churn. nathan 2017-09-12 Nathan Sidwell * name-lookup.c (get_class_binding): Rename TYPE arg to KLASS for consistency. (restort_data): Move later. (method_name_cmp, resort_method_name_cmp): Simplify. (resort_type_method_vec): Reformat. Index: name-lookup.c =================================================================== --- name-lookup.c (revision 252002) +++ name-lookup.c (working copy) @@ -1311,36 +1311,37 @@ get_class_binding_direct (tree klass, tr special function creation as necessary. */ tree -get_class_binding (tree type, tree name, int type_or_fns) +get_class_binding (tree klass, tree name, int type_or_fns) { - type = complete_type (type); + klass = complete_type (klass); - if (COMPLETE_TYPE_P (type)) + if (COMPLETE_TYPE_P (klass)) { + /* Lazily declare functions, if we're going to search these. */ if (IDENTIFIER_CTOR_P (name)) { - if (CLASSTYPE_LAZY_DEFAULT_CTOR (type)) - lazily_declare_fn (sfk_constructor, type); - if (CLASSTYPE_LAZY_COPY_CTOR (type)) - lazily_declare_fn (sfk_copy_constructor, type); - if (CLASSTYPE_LAZY_MOVE_CTOR (type)) - lazily_declare_fn (sfk_move_constructor, type); + if (CLASSTYPE_LAZY_DEFAULT_CTOR (klass)) + lazily_declare_fn (sfk_constructor, klass); + if (CLASSTYPE_LAZY_COPY_CTOR (klass)) + lazily_declare_fn (sfk_copy_constructor, klass); + if (CLASSTYPE_LAZY_MOVE_CTOR (klass)) + lazily_declare_fn (sfk_move_constructor, klass); } - else if (name == cp_assignment_operator_id (NOP_EXPR)) + else if (IDENTIFIER_DTOR_P (name)) { - if (CLASSTYPE_LAZY_COPY_ASSIGN (type)) - lazily_declare_fn (sfk_copy_assignment, type); - if (CLASSTYPE_LAZY_MOVE_ASSIGN (type)) - lazily_declare_fn (sfk_move_assignment, type); + if (CLASSTYPE_LAZY_DESTRUCTOR (klass)) + lazily_declare_fn (sfk_destructor, klass); } - else if (IDENTIFIER_DTOR_P (name)) + else if (name == cp_assignment_operator_id (NOP_EXPR)) { - if (CLASSTYPE_LAZY_DESTRUCTOR (type)) - lazily_declare_fn (sfk_destructor, type); + if (CLASSTYPE_LAZY_COPY_ASSIGN (klass)) + lazily_declare_fn (sfk_copy_assignment, klass); + if (CLASSTYPE_LAZY_MOVE_ASSIGN (klass)) + lazily_declare_fn (sfk_move_assignment, klass); } } - return get_class_binding_direct (type, name, type_or_fns); + return get_class_binding_direct (klass, name, type_or_fns); } /* Find the slot containing overloads called 'NAME'. If there is no @@ -1411,56 +1412,58 @@ get_method_slot (tree klass, tree name) return slot; } -static struct { - gt_pointer_operator new_value; - void *cookie; -} resort_data; - -/* Comparison function to compare two TYPE_METHOD_VEC entries by name. */ +/* Comparison function to compare two TYPE_METHOD_VEC entries by + name. */ static int -method_name_cmp (const void* m1_p, const void* m2_p) +method_name_cmp (const void *a_p, const void *b_p) { - const tree *const m1 = (const tree *) m1_p; - const tree *const m2 = (const tree *) m2_p; + tree a = *(const tree *)a_p; + tree b = *(const tree *)b_p; + tree name_a = DECL_NAME (TREE_CODE (a) == OVERLOAD ? OVL_FUNCTION (a) : a); + tree name_b = DECL_NAME (TREE_CODE (b) == OVERLOAD ? OVL_FUNCTION (b) : b); - if (OVL_NAME (*m1) < OVL_NAME (*m2)) - return -1; - return 1; + gcc_checking_assert (name_a && name_b && name_a != name_b); + return name_a < name_b ? -1 : +1; } +static struct { + gt_pointer_operator new_value; + void *cookie; +} resort_data; + /* This routine compares two fields like method_name_cmp but using the - pointer operator in resort_field_decl_data. */ + pointer operator in resort_field_decl_data. We don't have to deal + with duplicates here. */ static int -resort_method_name_cmp (const void* m1_p, const void* m2_p) +resort_method_name_cmp (const void *a_p, const void *b_p) { - const tree *const m1 = (const tree *) m1_p; - const tree *const m2 = (const tree *) m2_p; + tree a = *(const tree *)a_p; + tree b = *(const tree *)b_p; + tree name_a = OVL_NAME (a); + tree name_b = OVL_NAME (b); + + resort_data.new_value (&name_a, resort_data.cookie); + resort_data.new_value (&name_b, resort_data.cookie); + + gcc_checking_assert (name_a != name_b); - tree n1 = OVL_NAME (*m1); - tree n2 = OVL_NAME (*m2); - resort_data.new_value (&n1, resort_data.cookie); - resort_data.new_value (&n2, resort_data.cookie); - if (n1 < n2) - return -1; - return 1; + return name_a < name_b ? -1 : +1; } /* Resort TYPE_METHOD_VEC because pointers have been reordered. */ void -resort_type_method_vec (void* obj, - void* /*orig_obj*/, - gt_pointer_operator new_value, - void* cookie) +resort_type_method_vec (void *obj, void */*orig_obj*/, + gt_pointer_operator new_value, void* cookie) { if (vec *method_vec = (vec *) obj) { resort_data.new_value = new_value; resort_data.cookie = cookie; - qsort (method_vec->address (), method_vec->length (), sizeof (tree), - resort_method_name_cmp); + qsort (method_vec->address (), method_vec->length (), + sizeof (tree), resort_method_name_cmp); } }