Skip to content

Commit 46a0e43

Browse files
committed
reduce diff
1 parent aa084e7 commit 46a0e43

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

ext/bert/c/decode.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,9 @@ static VALUE rb_mBERT;
2727
static VALUE rb_cDecode;
2828
static VALUE rb_cTuple;
2929

30-
typedef struct bert_buf bert_buf;
31-
32-
typedef VALUE (*bert_ptr)(struct bert_buf *buf);
33-
3430
struct bert_buf {
3531
const uint8_t *data;
3632
const uint8_t *end;
37-
bert_ptr *callbacks;
3833
};
3934

4035
static VALUE bert_read_invalid(struct bert_buf *buf);
@@ -55,6 +50,7 @@ static VALUE bert_read_unicode_string(struct bert_buf *buf);
5550
static VALUE bert_read_sbignum(struct bert_buf *buf);
5651
static VALUE bert_read_lbignum(struct bert_buf *buf);
5752

53+
typedef VALUE (*bert_ptr)(struct bert_buf *buf);
5854
static bert_ptr bert_callbacks[] = {
5955
&bert_read_sint,
6056
&bert_read_int,
@@ -118,7 +114,7 @@ static VALUE bert_read(struct bert_buf *buf)
118114
if (!BERT_VALID_TYPE(type))
119115
rb_raise(rb_eRuntimeError, "Invalid tag '%d' for term", type);
120116

121-
return buf->callbacks[type - BERT_TYPE_OFFSET](buf);
117+
return bert_callbacks[type - BERT_TYPE_OFFSET](buf);
122118
}
123119

124120
static VALUE bert_read_dict(struct bert_buf *buf)
@@ -517,17 +513,11 @@ static VALUE rb_bert_decode(VALUE klass, VALUE rb_string)
517513
bert_buf_ensure(&buf, 1);
518514

519515
proto_version = bert_buf_read8(&buf);
520-
switch(proto_version) {
521-
case ERL_VERSION:
522-
buf.callbacks = bert_callbacks;
523-
break;
524-
case ERL_VERSION2:
525-
buf.callbacks = bert_callbacks;
526-
break;
527-
default:
528-
rb_raise(rb_eTypeError, "Invalid magic value for BERT string");
516+
if (proto_version == ERL_VERSION || proto_version == ERL_VERSION2) {
517+
return bert_read(&buf);
518+
} else {
519+
rb_raise(rb_eTypeError, "Invalid magic value for BERT string");
529520
}
530-
return bert_read(&buf);
531521
}
532522

533523
static VALUE rb_bert_impl(VALUE klass)

0 commit comments

Comments
 (0)