fast_underscore 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/ext/fast_underscore/fast_underscore.c +24 -9
- data/lib/fast_underscore/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c17dba8603583fe3bbf453105935b8096e5b2d203ee897c6dcbc615271cfc319
|
4
|
+
data.tar.gz: 59957bc68910d3cfb38b1bbf010f3cfd7136e75ef4869883f101386786454ae8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6eba585974debc3350e9308b326ef7c9c7060adca5fc02c9dd084561f05579ff39617ad71d88b6fa02d170c1bee4fc2f7d4b867e135e2fa79cb1dae66f4a1a3
|
7
|
+
data.tar.gz: adedbd73f9b7181c2648cfbe751e7bd716fc72dde0eef7ec2cf06fd33b06c393e2a282bdec55f0e1b59837457f8b537b99b3d13501439667f2bdd371d25de42a
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# `String#underscore` Ruby Extension
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/kddeisz/fast_underscore.svg?branch=master)](https://travis-ci.org/kddeisz/fast_underscore)
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/fast_underscore.svg)](fast_underscore)
|
5
|
+
|
3
6
|
`fast_underscore` is a simple C extension which provides a fast implementation of [Active Support's `String#underscore` method](http://api.rubyonrails.org/classes/String.html#method-i-underscore).
|
4
7
|
|
5
8
|
## Do I need this?
|
@@ -90,7 +90,9 @@ typedef struct builder {
|
|
90
90
|
*/
|
91
91
|
static codepoint_t*
|
92
92
|
codepoint_build(rb_encoding *encoding) {
|
93
|
-
codepoint_t *codepoint
|
93
|
+
codepoint_t *codepoint;
|
94
|
+
|
95
|
+
codepoint = (codepoint_t *) malloc(sizeof(codepoint_t));
|
94
96
|
if (codepoint == NULL) {
|
95
97
|
return NULL;
|
96
98
|
}
|
@@ -112,7 +114,9 @@ codepoint_free(codepoint_t *codepoint) {
|
|
112
114
|
*/
|
113
115
|
static builder_t*
|
114
116
|
builder_build(long str_len) {
|
115
|
-
builder_t *builder
|
117
|
+
builder_t *builder;
|
118
|
+
|
119
|
+
builder = (builder_t *) malloc(sizeof(builder_t));
|
116
120
|
if (builder == NULL) {
|
117
121
|
return NULL;
|
118
122
|
}
|
@@ -181,7 +185,9 @@ builder_segment_push(builder_t *builder, codepoint_t *codepoint) {
|
|
181
185
|
*/
|
182
186
|
static void
|
183
187
|
builder_segment_copy(builder_t *builder, long size) {
|
184
|
-
|
188
|
+
long idx;
|
189
|
+
|
190
|
+
for (idx = 0; idx < size; idx++) {
|
185
191
|
builder_result_push_literal(builder, builder->segment[idx]);
|
186
192
|
}
|
187
193
|
}
|
@@ -345,13 +351,21 @@ builder_free(builder_t *builder) {
|
|
345
351
|
*/
|
346
352
|
static VALUE
|
347
353
|
rb_str_underscore(VALUE self, VALUE rb_string) {
|
348
|
-
|
354
|
+
VALUE resultant;
|
355
|
+
rb_encoding *encoding;
|
356
|
+
|
357
|
+
char *string;
|
358
|
+
char *end;
|
359
|
+
|
360
|
+
builder_t *builder;
|
361
|
+
codepoint_t *codepoint;
|
349
362
|
|
350
|
-
|
351
|
-
|
363
|
+
encoding = rb_enc_from_index(ENCODING_GET(rb_string));
|
364
|
+
string = RSTRING_PTR(rb_string);
|
365
|
+
end = RSTRING_END(rb_string);
|
352
366
|
|
353
|
-
|
354
|
-
|
367
|
+
builder = builder_build(RSTRING_LEN(rb_string) * 2);
|
368
|
+
codepoint = codepoint_build(encoding);
|
355
369
|
|
356
370
|
while (string < end) {
|
357
371
|
codepoint->character = rb_enc_codepoint_len(string, end, &codepoint->size, encoding);
|
@@ -360,8 +374,9 @@ rb_str_underscore(VALUE self, VALUE rb_string) {
|
|
360
374
|
}
|
361
375
|
builder_flush(builder);
|
362
376
|
|
363
|
-
|
377
|
+
resultant = rb_enc_str_new(builder->result, builder->result_size, encoding);
|
364
378
|
builder_free(builder);
|
379
|
+
codepoint_free(codepoint);
|
365
380
|
|
366
381
|
return resultant;
|
367
382
|
}
|