git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 5/7] name-hash: perf improvement for lazy_init_name_hash

From
Stefan Beller <sbeller@google.com>
Date
Mar 23, 2017, 17:45 UTC
Message-ID
<CAGZ79kZKri4jsnGCWhpV_WjSef5DxSwMTxYOour9kjzTWOFcxA@mail.gmail.com>
In-Reply-To
<e987714e-473f-cad1-159b-18459ffeb241@ramsayjones.plus.com>

On Thu, Mar 23, 2017 at 8:25 AM, Ramsay Jones <ramsay@ramsayjones.plus.com> wrote:

Show 20 quoted lines
>> +static struct dir_entry *hash_dir_entry_with_parent_and_prefix(
>> +     struct index_state *istate,
>> +     struct dir_entry *parent,
>> +     struct strbuf *prefix)
>> +{
>> +     struct dir_entry *dir;
>> +     unsigned int hash;
>> +     int lock_nr;
>> +
>> +     /*
>> +      * Either we have a parent directory and path with slash(es)
>> +      * or the directory is an immediate child of the root directory.
>> +      */
>> +     assert((parent != NULL) ^ (strchr(prefix->buf, '/') == 0));
>
> sparse complains about 'Using plain integer as a NULL pointer', (the
> return from strchr() is NULL, if '/' is not found) so maybe:
>
> +       assert((parent != NULL) ^ (strchr(prefix->buf, '/') == NULL));
>

Also this seems part of the actual shipped code, not testing code. In that case we prefer

    if (<condition>)
        die("BUG: <description>");

This is because asserts may be omitted by the compiler, when compiled with NDEBUG.

However it is preferable to have these error checking code in the shipped product, as opposed to users running into that edge case and reporting an error which is totally non-obvious.

Thanks, Stefan

Previous: Ramsay JonesNext: Jeff Hostetler
Message 9 of 20 in “thread lazy_init_name_hash”
  1. 0/7 thread lazy_init_name_hashgit@jeffhostetler.com, Mar 23, 2017
  2. 2/7 hashmap: allow memihash computation to be continuedgit@jeffhostetler.com, Mar 23, 2017
  3. 6/7 name-hash: add test-lazy-init-name-hashgit@jeffhostetler.com, Mar 23, 2017
  4. Ramsay JonesMar 23, 2017
  5. 1/7 name-hash: specify initial size for istate.dir_hash tablegit@jeffhostetler.com, Mar 23, 2017
  6. 7/7 name-hash: add perf test for lazy_init_name_hashgit@jeffhostetler.com, Mar 23, 2017
  7. 5/7 name-hash: perf improvement for lazy_init_name_hashgit@jeffhostetler.com, Mar 23, 2017
  8. Ramsay JonesMar 23, 2017
  9. Stefan BellerMar 23, 2017
  10. Jeff HostetlerMar 24, 2017
  11. Junio C HamanoMar 27, 2017
  12. Jeff HostetlerMar 27, 2017
  13. 3/7 hashmap: Add disallow_rehash settinggit@jeffhostetler.com, Mar 23, 2017
  14. 4/7 hashmap: document memihash_cont, hashmap_disallow_rehash apigit@jeffhostetler.com, Mar 23, 2017
  15. Junio C HamanoMar 23, 2017
  16. Jeff HostetlerMar 24, 2017
  17. Stefan BellerMar 24, 2017
  18. Junio C HamanoMar 24, 2017
  19. Duy NguyenApr 6, 2017
  20. Jeff HostetlerApr 6, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.