Changeset 1b6b76d in mainline for uspace/app/bithenge/transform.c


Ignore:
Timestamp:
2012-08-12T05:10:17Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2988aec7
Parents:
6be4142
Message:

Bithenge: improve efficiency by making out_size optional in prefix_apply

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bithenge/transform.c

    r6be4142 r1b6b76d  
    143143 * @param[out] out_node Holds the result of applying this transform to the
    144144 * prefix.
    145  * @param[out] out_size Holds the size of the prefix.
     145 * @param[out] out_size Holds the size of the prefix. Can be null, in which
     146 * case the size is not determined.
    146147 * @return EOK on success, ENOTSUP if not supported, or another error code from
    147148 * errno.h. */
     
    158159                return ENOTSUP;
    159160
    160         int rc = bithenge_transform_prefix_length(self, scope, blob, out_size);
     161        aoff64_t size;
     162        int rc = bithenge_transform_prefix_length(self, scope, blob, &size);
    161163        if (rc != EOK)
    162164                return rc;
    163165        bithenge_node_t *prefix_blob;
    164166        bithenge_blob_inc_ref(blob);
    165         rc = bithenge_new_subblob(&prefix_blob, blob, 0, *out_size);
     167        rc = bithenge_new_subblob(&prefix_blob, blob, 0, size);
    166168        if (rc != EOK)
    167169                return rc;
    168170        rc = bithenge_transform_apply(self, scope, prefix_blob, out_node);
    169171        bithenge_node_dec_ref(prefix_blob);
     172        if (out_size)
     173                *out_size = size;
    170174        return rc;
    171175}
     
    560564{
    561565        char buffer;
    562         *out_size = 1;
    563         int rc = bithenge_blob_read_bits(blob, 0, &buffer, out_size, true);
    564         if (rc != EOK)
    565                 return rc;
    566         if (*out_size != 1)
    567                 return EINVAL;
     566        aoff64_t size = 1;
     567        int rc = bithenge_blob_read_bits(blob, 0, &buffer, &size, true);
     568        if (rc != EOK)
     569                return rc;
     570        if (size != 1)
     571                return EINVAL;
     572        if (out_size)
     573                *out_size = size;
    568574        return bithenge_new_boolean_node(out_node, (buffer & 1) != 0);
    569575}
     
    902908                return EINVAL;
    903909
    904         *out_size = num_bits;
     910        aoff64_t size = num_bits;
    905911        uint8_t buffer[sizeof(bithenge_int_t)];
    906         rc = bithenge_blob_read_bits(blob, 0, (char *)buffer, out_size,
     912        rc = bithenge_blob_read_bits(blob, 0, (char *)buffer, &size,
    907913            little_endian);
    908914        if (rc != EOK)
    909915                return rc;
    910         if (*out_size != (aoff64_t)num_bits)
    911                 return EINVAL;
     916        if (size != (aoff64_t)num_bits)
     917                return EINVAL;
     918        if (out_size)
     919                *out_size = size;
    912920
    913921        bithenge_int_t result = 0;
Note: See TracChangeset for help on using the changeset viewer.