This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v3][BZ #15346] Allow leading and trailing spaces in getdate


> @@ -135,6 +137,37 @@ __getdate_r (const char *string, struct tm *tp)
>    /* No threads reading this stream.  */
>    __fsetlocking (fp, FSETLOCKING_BYCALLER);
>  
> +  size_t inlen = strlen (string);
> +  int i = 0;
> +  bool free_instr = false;
> +
> +  /* Skip leading whitespace.  */
> +  while (isspace (string[i]))
> +    i++;
> +
> +  /* Skip trailing whitespace.  */
> +  while (inlen > i && isspace (string[inlen - 1]))
> +    inlen--;
> +
> +  inlen -= i;

Let's avoid the copy when it's unnecessary.  So, start incrementing STRING
itself for the leading whitespace (and don't do strlen til after that).
Then only do the copy if the trailing whitespace check found anything to trim.


Thanks,
Roland


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]