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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92b7e9dcd681e04772d2ebc6c19cb4b81754c30c15f2c5b11ea70f480b60de94
4
- data.tar.gz: 1dae29981eb5c68f39fe9f0d0840a4d2066c3a6e123ae2f68190e7244aae93c0
3
+ metadata.gz: c17dba8603583fe3bbf453105935b8096e5b2d203ee897c6dcbc615271cfc319
4
+ data.tar.gz: 59957bc68910d3cfb38b1bbf010f3cfd7136e75ef4869883f101386786454ae8
5
5
  SHA512:
6
- metadata.gz: e30d177a4285fe0486a995f83b7eba7e5d4bd11aa3b7c0ee25954364b28b57a9e02066e746271a3f4643cdbe6989e22a6b3587492f2820902eac062b1e490dc0
7
- data.tar.gz: ba43f899c1055930bc7a9e3ad9a4c7973fefd03668428e9d3ae48de6f7bcdb53abbf3beec1f50b89c317a17f1b4400f5abd664744e4eff526d0591694213b61b
6
+ metadata.gz: b6eba585974debc3350e9308b326ef7c9c7060adca5fc02c9dd084561f05579ff39617ad71d88b6fa02d170c1bee4fc2f7d4b867e135e2fa79cb1dae66f4a1a3
7
+ data.tar.gz: adedbd73f9b7181c2648cfbe751e7bd716fc72dde0eef7ec2cf06fd33b06c393e2a282bdec55f0e1b59837457f8b537b99b3d13501439667f2bdd371d25de42a
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
- rvm: 2.5.0
2
+ rvm: 2.4.3
3
3
  branches:
4
4
  only: master
5
5
  cache: bundler
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fast_underscore (0.0.1)
4
+ fast_underscore (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 = (codepoint_t *) malloc(sizeof(codepoint_t));
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 = (builder_t *) malloc(sizeof(builder_t));
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
- for (long idx = 0; idx < size; idx++) {
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
- rb_encoding *encoding = rb_enc_from_index(ENCODING_GET(rb_string));
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
- char *string = RSTRING_PTR(rb_string);
351
- char *end = RSTRING_END(rb_string);
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
- builder_t *builder = builder_build(RSTRING_LEN(rb_string) * 2);
354
- codepoint_t *codepoint = codepoint_build(encoding);
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
- VALUE resultant = rb_enc_str_new(builder->result, builder->result_size, encoding);
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
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastUnderscore
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_underscore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Deisz