Age | Commit message (Collapse) | Author |
|
characters
This affects sfeed_plain.
- Use unicode replacement character (codepoint 0xfffd) when a codepoint is
invalid and proceed printing the rest of the characters.
- When a codepoint is invalid reset the internal state of mbtowc(3), from the
OpenBSD man page:
" If a call to mbtowc() resulted in an undefined internal state, mbtowc()
must be called with s set to NULL to reset the internal state before it
can safely be used again."
- Optimize for the common ASCII case and use a macro to print the character
instead of a wasteful fwrite() function call. With 250k lines (+- 350MB) this
improves printing performance from 1.7s to 1.0s on my laptop. On an other
system it improved by +- 25%. Tested with clang and gcc and also tested the
worst-case (non-ASCII) with no penalty.
To test:
printf '0\tabc\xc3 def' | sfeed_plain
Before:
1970-01-01 01:00 abc
After:
1970-01-01 01:00 abc� def
|
|
Use putc instead of fputc, it can be optimized to macros.
From the OpenBSD man page:
" putc() acts essentially identically to fputc(), but is a macro that
expands in-line. It may evaluate stream more than once, so arguments
given to putc() should not be expressions with potential side effects."
sfeed_atom, sfeed_frames and sfeed_html are using this function.
Mini-benchmarked sfeed_html and it went from 1.45s to 1.0s with feed files in
total 250k lines (+- 350MB). Tested with clang and gcc on OpenBSD on an older
laptop.
|
|
|
|
iscntrl is c < ' ' || c == 127
I want to encode a space and everything above 127 also.
So this condition can be simplified to this.
|
|
- remove a check that has no use/can never happen.
- remove the return value as it's unused and the input size is known.
- fix an old comment that doesn't reflect what the function does anymore.
|
|
Optimize for the common-case: assuming ASCII.
The input is assumed to be valid UTF-8 input (output of sfeed).
This saves 2 function calls for determining the width of a single ASCII
character, which of course is 1.
Ranges:
< 32 are control-characters and are skipped.
< 127 is typical ASCII and is 1 column wide.
>= 127 is the normal path (control-character and multi-byte UTF-8).
Tested on OpenBSD and Linux with various compilers (clang, gcc, pcc and tcc).
On OpenBSD and Linux glibc much improvement. On Linux musl (almost) no change.
In a common-case upto 40% performance improvement.
In the worst-case negligible performance degration (<1%).
|
|
|
|
|
|
|
|
|
|
|
|
POSIX says about snprintf:
"If an output error was encountered, these functions shall return a
negative value".
So check for < 0 instead of -1. Afaik all implementations return -1 though.
|
|
|
|
|
|
- cast all ctype(3) function argument to (unsigned char) to avoid UB
POSIX says:
"The c argument is an int, the value of which the application shall ensure is a
character representable as an unsigned char or equal to the value of the macro
EOF. If the argument has any other value, the behavior is undefined."
Many libc cast implicitly the value, but NetBSD does not, which is probably the
correct thing to interpret it.
- no need to cast for putchar + rename some fputc(..., stdout) to putchar
POSIX says:
"The fputc() function shall write the byte specified by c (converted to an
unsigned char) to the output stream pointed to by stream [...]"
Major thanks to Leonardo Taccari <iamleot@gmail.com> for reporting and testing
it on NetBSD!
|
|
for example the string "\xef\xbc\xb5".
|
|
|
|
|
|
|
|
- use a UTF-8 ellipses (1 column width) for "...".
- do proper truncation at the specified length.
|
|
this entity is XHTML, it is not supported by some (older) browsers.
|
|
|
|
|
|
|
|
... as a bonus it also saves an allocation.
|
|
|
|
use long long: atleast 32-bit, but now time_t (real) to 32-bit or
64-bit is supported. Long long is C99 though, but that is fine.
check errno, it can have ERANGE.
|
|
|
|
|
|
- pledge tools and add define to enable it on platforms that support it, currently
only OpenBSD 5.9+
- separate getline and parseline functionality.
- use murmur3 hash instead of jenkins1: faster and less collisions.
- make some error messages a bit more clear, for example with path truncation.
- some small cleanups, move printutf8pad to util.
|
|
use the port specified in the link for urls starting with "//" (use protocol).
|
|
|
|
|
|
|
|
7f11ef506465896705f15c39bd0416d96ca651a8
|
|
|
|
as input: an empty string or non-digit characters are digits are considered an
error now. Still, for the format tools output the formatted time string as
time_t 0 on a parse error.
|
|
|
|
... put specific formatting-logic per program (printcontent()).
|
|
|
|
|
|
- Only escape characters in "content" field, these can contain newlines.
- Trim newlines and tabs, etc from the title, id and author fields.
- Make decodefield, xmlencode functions easier to "chain" without allocatting
new buffers.
- Move printutf8pad from util (only used by sfeed_plain) to sfeed_plain.
- Update README, still need to update the man-page and improve the documentation
in general.
- Code cleanup.
|
|
|
|
|
|
|
|
- don't print directly but use an internal buffer (also better for testing).
- encode uri when printing (security).
- add some comments.
|
|
|
|
|
|
|
|
|