syslog: I think this might speed upt the CR-LF scan in syslog_dev_write().

This commit is contained in:
Gregory Nutt
2017-05-12 08:50:56 -06:00
parent c84a3e3519
commit fc7c3f5328
+45 -44
View File
@@ -518,59 +518,60 @@ ssize_t syslog_dev_write(FAR const char *buffer, size_t buflen)
remaining > 0; remaining > 0;
endptr++, remaining--) endptr++, remaining--)
{ {
bool crlf = false; /* Check for carriage return or line feed */
/* Check for a CR-LF sequence */ if (*endptr == '\r' || *endptr == '\n')
if (remaining > 1 &&
((endptr[0] == '\r' && endptr[1] == '\n') ||
(endptr[0] == '\n' && endptr[1] == '\r')))
{ {
endptr++; /* Check for pre-formatted CR-LF sequence */
remaining--;
crlf = true;
}
/* Special case carriage return and line feed */ if (remaining > 1 &&
((endptr[0] == '\r' && endptr[1] == '\n') ||
if (!crlf && (*endptr == '\r' || *endptr == '\n')) (endptr[0] == '\n' && endptr[1] == '\r')))
{
/* Write everything up to this point, ignore the special
* character.
*
* - buffer points to next byte to output.
* - endptr points to the special character.
*/
writelen = (size_t)((uintptr_t)endptr - (uintptr_t)buffer);
if (writelen > 0)
{ {
nwritten = file_write(&g_syslog_dev.sl_file, buffer, writelen); /* Just skip over pre-formatted CR-LF or LF-CR sequence */
if (nwritten < 0)
{ endptr++;
errcode = -nwritten; remaining--;
goto errout_with_sem;
}
} }
else
/* Ignore the carriage return, but for the linefeed, output
* both a carriage return and a linefeed.
*/
if (*endptr == '\n')
{ {
nwritten = file_write(&g_syslog_dev.sl_file, g_syscrlf, 2); /* Write everything up to the position of the special
if (nwritten < 0) * character.
*
* - buffer points to next byte to output.
* - endptr points to the special character.
*/
writelen = (size_t)((uintptr_t)endptr - (uintptr_t)buffer);
if (writelen > 0)
{ {
errcode = -nwritten; nwritten = file_write(&g_syslog_dev.sl_file, buffer, writelen);
goto errout_with_sem; if (nwritten < 0)
{
errcode = -nwritten;
goto errout_with_sem;
}
} }
/* Ignore the carriage return, but for the linefeed, output
* both a carriage return and a linefeed.
*/
if (*endptr == '\n')
{
nwritten = file_write(&g_syslog_dev.sl_file, g_syscrlf, 2);
if (nwritten < 0)
{
errcode = -nwritten;
goto errout_with_sem;
}
}
/* Adjust pointers */
writelen++; /* Skip the special character */
buffer += writelen; /* Points past the special character */
} }
/* Adjust pointers */
writelen++; /* Skip the special character */
buffer += writelen; /* Points past the special character */
} }
} }