Re: [PATCH 10/23] fsmonitor--daemon: add pathname classification
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Apr 26, 2021, 20:24 UTC
- Message-ID
- <9a9d6da0-1a31-c04a-f41f-de20d85996b2@gmail.com>
- In-Reply-To
- <CAPig+cT1yz-M1MYTx1_HQRYe+Ryy=vzwtRgkhkX7bTYDB5rnkA@mail.gmail.com>
On 4/26/2021 4:11 PM, Eric Sunshine wrote:
Show 15 quoted lines
> On Mon, Apr 26, 2021 at 3:17 PM Derrick Stolee <stolee@gmail.com> wrote:
>> On 4/1/2021 11:40 AM, Jeff Hostetler via GitGitGadget wrote:
>>> +#define FSMONITOR_COOKIE_PREFIX ".fsmonitor-daemon-"
>>> +
>>> + if (!fspathncmp(rel, FSMONITOR_COOKIE_PREFIX,
>>> + strlen(FSMONITOR_COOKIE_PREFIX)))
>>
>> Seems like this strlen() could be abstracted out. Is it
>> something the compiler can compute and set for us? Or,
>> should we create a macro for this constant?
>
> If you're asking whether the compiler will resolve strlen("literal
> string") to an integer constant at compile time rather than computing
> the length at runtime, then the answer is that on this project we
> presume that the compiler is smart enough to do that.That is what I was asking.
> Or are you asking for a function something like this? > > fspathhasprefix(rel, FSMONITOR_COOKIE_PREFIX)
The "fix" I would recommend otherwise would be
if (!fspathncmp(rel, FSMONITOR_COOKIE_PREFIX, FSMONITOR_COOKIE_PREFIX_LEN))
which is much uglier. I'm glad we can trust the compiler to be smart enough.
Thanks, -Stolee