LCOV - code coverage report
Current view: top level - Objects/stringlib - count.h (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit 5e6661bce9] Lines: 6 9 66.7 %
Date: 2023-03-20 08:15:36 Functions: 1 4 25.0 %
Branches: 3 8 37.5 %

           Branch data     Line data    Source code
       1                 :            : /* stringlib: count implementation */
       2                 :            : 
       3                 :            : #ifndef STRINGLIB_FASTSEARCH_H
       4                 :            : #error must include "stringlib/fastsearch.h" before including this module
       5                 :            : #endif
       6                 :            : 
       7                 :            : // gh-97982: Implementing asciilib_count() is not worth it, FASTSEARCH() does
       8                 :            : // not specialize the code for ASCII strings. Use ucs1lib_count() for ASCII and
       9                 :            : // UCS1 strings: it's the same than asciilib_count().
      10                 :            : #if !STRINGLIB_IS_UNICODE || STRINGLIB_MAX_CHAR > 0x7Fu
      11                 :            : 
      12                 :            : Py_LOCAL_INLINE(Py_ssize_t)
      13                 :       5326 : STRINGLIB(count)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
      14                 :            :                 const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
      15                 :            :                 Py_ssize_t maxcount)
      16                 :            : {
      17                 :            :     Py_ssize_t count;
      18                 :            : 
      19         [ -  + ]:       5326 :     if (str_len < 0)
      20                 :          0 :         return 0; /* start > len(str) */
      21         [ -  + ]:       5326 :     if (sub_len == 0)
      22         [ #  # ]:          0 :         return (str_len < maxcount) ? str_len + 1 : maxcount;
      23                 :            : 
      24                 :       5326 :     count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
      25                 :            : 
      26         [ -  + ]:       5326 :     if (count < 0)
      27                 :          0 :         return 0; /* no match */
      28                 :            : 
      29                 :       5326 :     return count;
      30                 :            : }
      31                 :            : 
      32                 :            : #endif

Generated by: LCOV version 1.14