summaryrefslogtreecommitdiffstats
path: root/lib/buffer.c
Commit message (Collapse)AuthorAgeFilesLines
* Add an explicit cast to avoid a warningMiloslav Trmač2012-07-301-1/+1
| | | | | | ... with -Wsign-compare. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
* Remove escape_buffer entirelyGergely Nagy2012-06-221-25/+7
| | | | | | | | | | | | Output the escaped content directly into the destination buffer, avoiding the memory copy and associated overhead. This finishes the series, and brings another 6.6-18.0% speed improvement in test_perf, compared to the previous increase with using a static exception map. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Escape values directly into a bufferGergely Nagy2012-06-221-25/+55
| | | | | | | | Instead of precomputing a buffer length, do only one pass, extending the buffer as necessary. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Use pointers instead of offsets in ul_buffer_tGergely Nagy2012-06-221-27/+28
| | | | | | | This avoids various additions and subtractions on the fast path. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Simplify extending the bufferGergely Nagy2012-06-221-26/+35
| | | | | | | | | Most of the callers know how much the buffer needs extending, so don't ask them for the total size: new _ul_buffer_reserve_size replaces _ul_buffer_ensure_size, and the fast path is now inlined. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Change return type of _ul_str_escapeMiloslav Trmač2012-06-221-11/+8
| | | | | | | Use an integer instead of pointer, like in the other cases in buffer.c. We won't need the return value in the future. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
* Fix error handling in buffer.cGergely Nagy2012-06-221-26/+30
| | | | | | | | | | | | | * Don't lose old msg on realloc() failure * Don't dereference NULL on failure when buffer = (...) if (!buffer) { buffer->len = orig_len; ...} * To avoid the above pattern, use integer return values: "buffer" itself will not change in any case. * Add missing error handling Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Use a static exception mapGergely Nagy2012-06-221-51/+25
| | | | | | | | | | | | | | * Make the map static, read-only and preinitialized, to avoid thread-safety problems. * Invert the map, making it non-zero for exceptional characters (so that non-exceptional characters don't need to be mentioned) * Tighten the set of exceptional characters, so that most of ASCII goes through the fast path. This increases the speed of test_perf_* by 7.7-20.6%. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Don't use \f in JSONGergely Nagy2012-06-221-4/+0
| | | | | | | JSON-c 0.9 does not parse \f, so fall back to \uNNNN for now. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Fix 1-byte heap overflow in ul_buffer_finalizeMiloslav Trmač2012-06-221-2/+6
| | | | Signed-off-by: Miloslav Trmač <mitr@redhat.com>
* Remove an unnecessary pointer to arrayMiloslav Trmač2012-06-221-1/+1
| | | | | | | Be a little more explicit instead of relying on the compiler to optimize the variable away. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
* Reduce the number of memory allocationsGergely Nagy2012-04-291-14/+32
| | | | | | | | Make the string escape use an ul_buffer_t, to avoid unnecessary memory allocations. This greatly reduces the number of mallocs made, and thus results in a noticable increase in speed. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
* Improve string escape performance a littleGergely Nagy2012-04-161-6/+5
| | | | | | | | | | Instead of escaping a string, returning a new one and running strlen() on that, use an output variable to store the length, since we can easily calculate that during the escape process anyway. This should shave off a tiny bit of CPU time. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Correctly NULL-terminate the JSON buffer in all cases.Gergely Nagy2012-04-131-1/+1
| | | | | | | When finalizing the JSON buffer, always NULL-terminate it at the appropriate length. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Implement string escaping.Gergely Nagy2012-04-131-7/+132
| | | | | | With this patch, both JSON keys and values will be properly escaped. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Fix ul_buffer_finalize().Gergely Nagy2012-04-131-2/+3
| | | | | | | ul_buffer_finalize() was off by one, and instead of overriding the trailing ",", it overwrote the trailing nul-byte. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Format JSON ourselves, without json-c.Gergely Nagy2012-04-131-0/+94
To make the library thinner, we now format JSON ourselves: there was so little we used from json-c, that doing it ourselves is lighter and faster. With this commit, we have the architecture in place, with only a few little things remaining to be done, such as escaping string values. Signed-off-by: Gergely Nagy <algernon@balabit.hu>