Gitweb links:

...log 
http://git.netsurf-browser.org/libnsgif.git/shortlog/fada1a850cb1e88b9c19e45029092311ab7f869c
...commit 
http://git.netsurf-browser.org/libnsgif.git/commit/fada1a850cb1e88b9c19e45029092311ab7f869c
...tree 
http://git.netsurf-browser.org/libnsgif.git/tree/fada1a850cb1e88b9c19e45029092311ab7f869c

The branch, tlsa/lzw-optimise has been updated
       via  fada1a850cb1e88b9c19e45029092311ab7f869c (commit)
      from  9be2acf63d9f293d0ca1321dfd985889bce4e37d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/libnsgif.git/commit/?id=fada1a850cb1e88b9c19e45029092311ab7f869c
commit fada1a850cb1e88b9c19e45029092311ab7f869c
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    lzw: Optimisation: Pre-multiply relative offsets by struct size.

diff --git a/src/lzw.c b/src/lzw.c
index 59c74a6..fe79556 100644
--- a/src/lzw.c
+++ b/src/lzw.c
@@ -364,7 +364,7 @@ static inline void lzw__table_add_entry(
        entry->value = code;
        entry->first = ctx->prev_code_first;
        entry->count = ctx->prev_code_count + 1;
-       entry->extends = ctx->table_size - ctx->prev_code;
+       entry->extends = (ctx->table_size - ctx->prev_code) * sizeof(*entry);
 
        ctx->table_size++;
 }
@@ -444,6 +444,19 @@ static inline lzw_result lzw__decode(
 }
 
 /**
+ * Get the LZW table entry that the given entry extends.
+ *
+ * \param[in] entry  The starting entry/
+ * \return new table entry.
+ */
+static inline const struct lzw_table_entry *lzw__entry_get_extends(
+               const struct lzw_table_entry *entry)
+{
+       return (const struct lzw_table_entry *)
+                       (((const uint8_t *)(entry)) - entry->extends);
+}
+
+/**
  * Write values for this code to the output stack.
  *
  * If there isn't enough space in the output stack, this function will write
@@ -483,13 +496,13 @@ static inline uint32_t lzw__write_fn(struct lzw_ctx *ctx,
 
        /* Skip over any values we don't have space for. */
        for (unsigned i = left; i != 0; i--) {
-               entry -= entry->extends;
+               entry = lzw__entry_get_extends(entry);
        }
 
        output_pos += count;
        for (unsigned i = count; i != 0; i--) {
                *--output_pos = entry->value;
-               entry -= entry->extends;
+               entry = lzw__entry_get_extends(entry);
        }
 
        return count;
@@ -561,7 +574,7 @@ static inline uint32_t lzw__map_write_fn(struct lzw_ctx 
*ctx,
        ctx->output_left = left;
 
        for (unsigned i = left; i != 0; i--) {
-               entry -= entry->extends;
+               entry = lzw__entry_get_extends(entry);
        }
 
        output_pos += count;
@@ -571,12 +584,12 @@ static inline uint32_t lzw__map_write_fn(struct lzw_ctx 
*ctx,
                        if (entry->value != ctx->transparency_idx) {
                                *output_pos = ctx->colour_map[entry->value];
                        }
-                       entry -= entry->extends;
+                       entry = lzw__entry_get_extends(entry);
                }
        } else {
                for (unsigned i = count; i != 0; i--) {
                        *--output_pos = ctx->colour_map[entry->value];
-                       entry -= entry->extends;
+                       entry = lzw__entry_get_extends(entry);
                }
        }
 


-----------------------------------------------------------------------

Summary of changes:
 src/lzw.c |   25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/lzw.c b/src/lzw.c
index 59c74a6..fe79556 100644
--- a/src/lzw.c
+++ b/src/lzw.c
@@ -364,7 +364,7 @@ static inline void lzw__table_add_entry(
        entry->value = code;
        entry->first = ctx->prev_code_first;
        entry->count = ctx->prev_code_count + 1;
-       entry->extends = ctx->table_size - ctx->prev_code;
+       entry->extends = (ctx->table_size - ctx->prev_code) * sizeof(*entry);
 
        ctx->table_size++;
 }
@@ -444,6 +444,19 @@ static inline lzw_result lzw__decode(
 }
 
 /**
+ * Get the LZW table entry that the given entry extends.
+ *
+ * \param[in] entry  The starting entry/
+ * \return new table entry.
+ */
+static inline const struct lzw_table_entry *lzw__entry_get_extends(
+               const struct lzw_table_entry *entry)
+{
+       return (const struct lzw_table_entry *)
+                       (((const uint8_t *)(entry)) - entry->extends);
+}
+
+/**
  * Write values for this code to the output stack.
  *
  * If there isn't enough space in the output stack, this function will write
@@ -483,13 +496,13 @@ static inline uint32_t lzw__write_fn(struct lzw_ctx *ctx,
 
        /* Skip over any values we don't have space for. */
        for (unsigned i = left; i != 0; i--) {
-               entry -= entry->extends;
+               entry = lzw__entry_get_extends(entry);
        }
 
        output_pos += count;
        for (unsigned i = count; i != 0; i--) {
                *--output_pos = entry->value;
-               entry -= entry->extends;
+               entry = lzw__entry_get_extends(entry);
        }
 
        return count;
@@ -561,7 +574,7 @@ static inline uint32_t lzw__map_write_fn(struct lzw_ctx 
*ctx,
        ctx->output_left = left;
 
        for (unsigned i = left; i != 0; i--) {
-               entry -= entry->extends;
+               entry = lzw__entry_get_extends(entry);
        }
 
        output_pos += count;
@@ -571,12 +584,12 @@ static inline uint32_t lzw__map_write_fn(struct lzw_ctx 
*ctx,
                        if (entry->value != ctx->transparency_idx) {
                                *output_pos = ctx->colour_map[entry->value];
                        }
-                       entry -= entry->extends;
+                       entry = lzw__entry_get_extends(entry);
                }
        } else {
                for (unsigned i = count; i != 0; i--) {
                        *--output_pos = ctx->colour_map[entry->value];
-                       entry -= entry->extends;
+                       entry = lzw__entry_get_extends(entry);
                }
        }
 


-- 
NetSurf GIF Decoder
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to