Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3091422imu; Sun, 23 Dec 2018 15:55:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN5LyfUk/T8ywyoPNbJn8xDaXs7c351awwIu2HOfJW3OTYuK6KVQ62lqyFHqKNlsbyB2KYbq X-Received: by 2002:a17:902:6bc9:: with SMTP id m9mr10934196plt.173.1545609328862; Sun, 23 Dec 2018 15:55:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545609328; cv=none; d=google.com; s=arc-20160816; b=0lb9esNTyzDsrChjEJNC0dK+ICQhJWnpbh+/PVoyY1W5j1hJ16/YZv0nN7as3Z1/F5 ezj6azqeVSN2/vMZ3/mhhCxDq8ag5o/f20dElSCuPTjHudRfX0AfKnNRweoQRQN6PiOm Ahq3G3aPdZoCfZNzZCKMdfsriXLIjmI1EmPDj88ZE0vpUKk8QhQWIVzKyW81TQCEaz6F 2Ik6UeG6sg5xbwhpkGvBcWkhtkF9YBsZYavm9sVpCNf1ECfWSUAsZQEQ/344xkYEpFqd XeAf/A3H6EKuemTcOR9pAkcQcoQtTN22lkNqddgTPZBPB+hGKxLNd9aEnWy+hWLJeYqD HVFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=i9YIMAFeh7qv+am2vg/TEw3E+8x98DBXojDGkNaNmCs=; b=sZIJ0GTV13c0tkgsvFX2BNcC3fRZm3saBf7ZxzQd+GrKxVWQgiZpiRWTV28Kjg6z6q PpPIvY91CHguYexDTQyvpIbjHXcad+RFN8ZausMbuTBsdi0bysmPTi8sgzu7i7sdk00f BabzyBmZJMDBI5TUA+zorooSFjIU1U30fXRebzs+EVTv1HAdX1tnDugQmZOufL9fSiiw WfGGb5mw05ScSnjO7tHug5Gkx7oCtSXLyXtI+Hpci8ddLQ3O2G6CaRTOekoicWeROSWu zWn6+FsN1/I7pPxE+g6hUuBtiSyO2ewbj4jlu4k9e/NhCAQy9XKmeFvyZLW8Gn8GUtxM 1Ohg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=TaFMD1vW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f34si24125707ple.280.2018.12.23.15.54.43; Sun, 23 Dec 2018 15:55:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=TaFMD1vW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726151AbeLWXwS (ORCPT + 99 others); Sun, 23 Dec 2018 18:52:18 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:35831 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725911AbeLWXwR (ORCPT ); Sun, 23 Dec 2018 18:52:17 -0500 Received: by mail-ed1-f65.google.com with SMTP id x30so9046742edx.2 for ; Sun, 23 Dec 2018 15:52:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=i9YIMAFeh7qv+am2vg/TEw3E+8x98DBXojDGkNaNmCs=; b=TaFMD1vWecALSjayVF/bSQYdYUYmsDQlLlE7JWZYJMJxvhs3zMkXStKTtDhvo6CXZ2 ojRYCjblHOnTFtITBqEbB9LrK2j3ZBAhlt5DBco1Gm4fFBCXb79FW+K39LlU7tGbhSrT MI3/h2CKmwyzOJtNghkeFkSwt9MzxLtRXRCdM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=i9YIMAFeh7qv+am2vg/TEw3E+8x98DBXojDGkNaNmCs=; b=R1jkFfNIVn7OftrUWdy9lnG7m3O9VMGuk0p578b8SyVrmylXkZzO17vehktYwTG3Ny 63c/PPZEQVlvgbJGdW2RM+92gesAAE8FYdcu0PmY0A5lv9M0qSf6j2YRQsB1PyXInBQN 0T1t+ddIRJv1HGwc+3hKQXUbdEXSp4xTjR9x0H6Ypj7e/wPyvYD3obovUHObVnAz798K lLLi+CsG0KRQEe6BwbCqErHJj64J00p6NcD+U8Vkw5GkvgexKfWSyMk4D37GLB2i/HT/ bLEZL1RjfwOENqLyHtQmVhSXhEwvfgfVA8lnpHa/hiow4JT9vhH7BUZ6OtX+UxqJwj8R 8n6w== X-Gm-Message-State: AA+aEWb8QUZZhLb0Rhj2GOm73c12IbldlehiGrhpcSI0V3D2Msn32S9M cgWueq0EEqkFsQ/voA0bSc+Nog== X-Received: by 2002:a50:8863:: with SMTP id c32mr8555922edc.156.1545609135678; Sun, 23 Dec 2018 15:52:15 -0800 (PST) Received: from [192.168.0.189] (ip-5-186-119-68.cgn.fibianet.dk. [5.186.119.68]) by smtp.gmail.com with ESMTPSA id t24sm8664472edb.7.2018.12.23.15.52.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Dec 2018 15:52:15 -0800 (PST) Subject: Re: [for-next][PATCH 23/24] string.h: Add strncmp_prefix() helper macro To: Steven Rostedt , Rasmus Villemoes Cc: Joe Perches , Andreas Schwab , Linus Torvalds , Linux List Kernel Mailing , Ingo Molnar , Andrew Morton , Namhyung Kim , Masami Hiramatsu , Tom Zanussi , Greg Kroah-Hartman References: <20181221175618.968519903@goodmis.org> <20181221175659.208858193@goodmis.org> <20181221144054.20bdeb33@gandalf.local.home> <20181221153526.5e6055ca@gandalf.local.home> <077eeb8b09baebe78822819b5f15d671b738a2b2.camel@perches.com> <20181221155435.38a9a221@gandalf.local.home> <871s6ad2br.fsf@igel.home> <20181221160826.34c544e6@gandalf.local.home> <84199633fd49db573c9ba71f1992936422e907d4.camel@perches.com> <098d7abf-5b62-6a01-a370-97d96bece299@rasmusvillemoes.dk> <20181223175621.4e4d958c@vmware.local.home> From: Rasmus Villemoes Message-ID: <4daf3688-ea36-627a-cd8a-8f9bc6cabc56@rasmusvillemoes.dk> Date: Mon, 24 Dec 2018 00:52:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181223175621.4e4d958c@vmware.local.home> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/12/2018 23.56, Steven Rostedt wrote: > On Sun, 23 Dec 2018 23:01:52 +0100 > Rasmus Villemoes wrote: > >> On 21/12/2018 23.20, Joe Perches wrote: >>> >>> Using >>> >>> static inline bool str_has_prefix(const char *str, const char prefix[]) >>> { >>> return !strncmp(str, prefix, strlen(prefix)); >>> } >>> >> >> We already have exactly that function, it's called strstarts(). > > It's not exact. Huh? The str_has_prefix() I quoted is exactly strstarts(). > > Well, one thing that str_has_prefix() does that strstarts() does not, > is to return the prefix length which gets rid of the duplication. I hadn't seen the patches containing that version of str_has_prefix(). Anyway, I just wanted to point out that strstarts() exists, so that we at least do not add a copy of that. > Would it be OK to convert strstarts() to return the length of prefix? Dunno. By far, most users of the strncmp() idiom only seem to be interested in the boolean result. It's true that there are some that then want to skip the prefix and do further parsing, and I can see how avoiding duplicating the prefix length is useful. But the mathematician in me can't help consider the corner case of 'the empty string is always a prefix of any other string', and having str_has_prefix(str, "") be false seems wrong - obviously, nobody would ever use a literal "" there, but nothing in str_has_prefix() _requires_ the prefix to be a constant. Maybe 'bool str_skip_prefix(const char *s, const char *p, const char **out)' where *out is set to s+len on success, and set to s on failure (just to allow passing &s and continue parsing in elseifs)? That would make your 4/5 "tracing: Have the historgram use the result of str_has_prefix() for len of prefix" do if (str_skip_prefix(str, "onmatch(", &action_str)) { hoisting the action_str declaration to the top, replacing the len variable? Rasmus