Changeset 1b6b76d in mainline


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

Location:
uspace/app/bithenge
Files:
4 edited

Legend:

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

    r6be4142 r1b6b76d  
    287287        if (bithenge_node_type(in) != BITHENGE_NODE_BLOB)
    288288                return EINVAL;
    289         uint64_t size;
    290289        return bithenge_transform_prefix_apply(self->xform, scope,
    291             bithenge_node_as_blob(in), out, &size);
     290            bithenge_node_as_blob(in), out, NULL);
    292291}
    293292
  • uspace/app/bithenge/expression.c

    r6be4142 r1b6b76d  
    970970{
    971971        expression_transform_t *self = transform_as_expression(base);
    972         *out_size = 0;
     972        if (out_size)
     973                *out_size = 0;
    973974        return bithenge_expression_evaluate(self->expr, scope, out_node);
    974975}
  • uspace/app/bithenge/sequence.c

    r6be4142 r1b6b76d  
    546546                return rc;
    547547
    548         rc = seq_node_field_offset(node_as_seq(*out_node), out_size,
    549             self->num_subtransforms);
    550         if (rc != EOK) {
    551                 bithenge_node_dec_ref(*out_node);
    552                 return rc;
     548        if (out_size) {
     549                rc = seq_node_field_offset(node_as_seq(*out_node), out_size,
     550                    self->num_subtransforms);
     551                if (rc != EOK) {
     552                        bithenge_node_dec_ref(*out_node);
     553                        return rc;
     554                }
    553555        }
    554556
     
    815817                return rc;
    816818
    817         bithenge_int_t count = node_as_repeat(*out_node)->count;
    818         if (count != -1) {
    819                 rc = seq_node_field_offset(node_as_seq(*out_node), out_size, count);
    820                 if (rc != EOK) {
    821                         bithenge_node_dec_ref(*out_node);
    822                         return rc;
    823                 }
    824         } else {
    825                 *out_size = 0;
    826                 for (count = 1; ; count++) {
    827                         aoff64_t size;
     819        if (out_size) {
     820                bithenge_int_t count = node_as_repeat(*out_node)->count;
     821                if (count != -1) {
    828822                        rc = seq_node_field_offset(node_as_seq(*out_node),
    829                             &size, count);
    830                         if (rc != EOK)
    831                                 break;
    832                         *out_size = size;
     823                            out_size, count);
     824                        if (rc != EOK) {
     825                                bithenge_node_dec_ref(*out_node);
     826                                return rc;
     827                        }
     828                } else {
     829                        *out_size = 0;
     830                        for (count = 1; ; count++) {
     831                                aoff64_t size;
     832                                rc = seq_node_field_offset(
     833                                    node_as_seq(*out_node), &size, count);
     834                                if (rc != EOK)
     835                                        break;
     836                                *out_size = size;
     837                        }
    833838                }
    834839        }
     
    10871092                return rc;
    10881093
    1089         rc = bithenge_node_for_each(*out_node, for_each_noop, NULL);
    1090         if (rc != EOK) {
    1091                 bithenge_node_dec_ref(*out_node);
    1092                 return rc;
    1093         }
    1094 
    1095         rc = seq_node_field_offset(node_as_seq(*out_node), out_size,
    1096             node_as_do_while(*out_node)->count);
    1097         if (rc != EOK) {
    1098                 bithenge_node_dec_ref(*out_node);
    1099                 return rc;
     1094        if (out_size) {
     1095                rc = bithenge_node_for_each(*out_node, for_each_noop, NULL);
     1096                if (rc != EOK) {
     1097                        bithenge_node_dec_ref(*out_node);
     1098                        return rc;
     1099                }
     1100
     1101                rc = seq_node_field_offset(node_as_seq(*out_node), out_size,
     1102                    node_as_do_while(*out_node)->count);
     1103                if (rc != EOK) {
     1104                        bithenge_node_dec_ref(*out_node);
     1105                        return rc;
     1106                }
    11001107        }
    11011108
  • 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.