Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 9d50460

Browse files
committed
swap capacity and len in all string- and vector-like classes
1 parent 45c81d8 commit 9d50460

File tree

19 files changed

+81
-64
lines changed

19 files changed

+81
-64
lines changed

bytes.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ namespace lib_ruby_parser
1313
{
1414
public:
1515
char *ptr;
16-
size_t len;
1716
size_t capacity;
17+
size_t len;
1818

1919
ByteList() = delete;
2020
ByteList(char *ptr, size_t len, size_t capacity);

codegen/codegen/message_rs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ pub extern \"C\" fn LIB_RUBY_PARSER_drop_message(message: *mut DiagnosticMessage
4949
#[cfg(feature = \"tests\")]
5050
#[no_mangle]
5151
pub extern \"C\" fn lib_ruby_parser__test__make_message_list() -> DiagnosticMessageListBlob {
52-
DiagnosticMessageListBlob::from(helpers::make_messages())
52+
let mut v = helpers::make_messages();
53+
v.reserve(10);
54+
DiagnosticMessageListBlob::from(v)
5355
}
5456
5557
#[no_mangle]

codegen/codegen/messages_hpp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ namespace lib_ruby_parser
8181
{
8282
public:
8383
DiagnosticMessage *ptr;
84-
size_t len;
8584
size_t capacity;
85+
size_t len;
8686
8787
DiagnosticMessageList() = delete;
8888
DiagnosticMessageList(DiagnosticMessage *ptr, size_t len, size_t capacity);

codegen/codegen/node_rs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ pub extern \"C\" fn LIB_RUBY_PARSER_drop_node(node: *mut Node) {
7171
#[cfg(feature = \"tests\")]
7272
#[no_mangle]
7373
pub extern \"C\" fn lib_ruby_parser__test__make_node_list() -> NodeListBlob {
74-
NodeListBlob::from(helpers::make_nodes())
74+
let mut v = helpers::make_nodes();
75+
v.reserve(10);
76+
NodeListBlob::from(v)
7577
}
7678
7779
#[no_mangle]

codegen/codegen/nodes_hpp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ namespace lib_ruby_parser
1717
{
1818
public:
1919
Node *ptr;
20-
size_t len;
2120
size_t capacity;
21+
size_t len;
2222
2323
NodeList() = delete;
2424
NodeList(Node *ptr, size_t len, size_t capacity);

comment.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ namespace lib_ruby_parser
4949
{
5050
public:
5151
Comment *ptr;
52-
size_t len;
5352
size_t capacity;
53+
size_t len;
5454

5555
CommentList() = delete;
5656
CommentList(Comment *ptr, size_t len, size_t capacity);

diagnostic.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ namespace lib_ruby_parser
6262
{
6363
public:
6464
Diagnostic *ptr;
65-
size_t len;
6665
size_t capacity;
66+
size_t len;
6767

6868
DiagnosticList() = delete;
6969
DiagnosticList(Diagnostic *ptr, size_t len, size_t capacity);

magic_comment.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ namespace lib_ruby_parser
4444
{
4545
public:
4646
MagicComment *ptr;
47-
size_t len;
4847
size_t capacity;
48+
size_t len;
4949

5050
MagicCommentList() = delete;
5151
MagicCommentList(MagicComment *ptr, size_t len, size_t capacity);

ruby-parser-cpp/src/bytes.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ blob_type!(BytesBlob, Bytes);
77
#[cfg(feature = "tests")]
88
#[no_mangle]
99
pub extern "C" fn lib_ruby_parser__test__make_byte_list(i1: u8, i2: u8, i3: u8) -> ByteListBlob {
10-
ByteListBlob::from(vec![i1, i2, i3])
10+
let mut v = vec![i1, i2, i3];
11+
v.reserve(10);
12+
ByteListBlob::from(v)
1113
}
1214

1315
#[no_mangle]
@@ -18,7 +20,9 @@ pub extern "C" fn LIB_RUBY_PARSER_drop_byte_list(byte_list: *mut Vec<u8>) {
1820
#[cfg(feature = "tests")]
1921
#[no_mangle]
2022
pub extern "C" fn lib_ruby_parser__test__make_bytes(i1: u8, i2: u8, i3: u8) -> BytesBlob {
21-
BytesBlob::from(Bytes::new(vec![i1, i2, i3]))
23+
let mut v = vec![i1, i2, i3];
24+
v.reserve(10);
25+
BytesBlob::from(Bytes::new(v))
2226
}
2327

2428
#[no_mangle]

ruby-parser-cpp/src/comment.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ pub extern "C" fn lib_ruby_parser__test__make_comment(location: Loc, kind: Comme
3434
#[cfg(feature = "tests")]
3535
#[no_mangle]
3636
pub extern "C" fn lib_ruby_parser__test__make_comment_list(comment: Comment) -> CommentListBlob {
37-
CommentListBlob::from(vec![comment])
37+
let mut v = vec![comment];
38+
v.reserve(10);
39+
CommentListBlob::from(v)
3840
}
3941

4042
#[no_mangle]

0 commit comments

Comments
 (0)