fast_activesupport 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/fast_activesupport/extconf.rb +3 -0
- data/ext/fast_activesupport/fast_activesupport.c +19 -0
- data/ext/fast_activesupport/fast_activesupport_utils.c +25 -0
- data/ext/fast_activesupport/fast_activesupport_utils.h +2 -0
- data/ext/fast_activesupport/security_utils.c +57 -0
- data/ext/fast_activesupport/security_utils.h +1 -0
- data/fast_activesupport.gemspec +31 -0
- data/lib/fast_activesupport.rb +6 -0
- data/lib/fast_activesupport/version.rb +3 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '098b2c48c05b148adbbb5160304199445fa09f339c031cdc4095e1441620ae7b'
|
4
|
+
data.tar.gz: 87985856ab27fa8234c98a0944a92b2b87e6b48d6fa14d748c0c56e75eaf169f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c7a4239c17717e238e00b0805178851813788d30ef82ee2520da267c33f60cea1419b74c6eb5f938b4da8869f51fa55a0126da531904d234234b5372f858e601
|
7
|
+
data.tar.gz: df13a8c51fe43b347e3ca057d02f03cc19457104f0e488968432062e554f34881f2c0e9f6a04671672d3faf011e16195ca6cd2a468bdab15ce123ac330d7792e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fast_activesupport (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
benchmark-ips (2.7.2)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
rake (10.5.0)
|
12
|
+
rake-compiler (1.0.4)
|
13
|
+
rake
|
14
|
+
rspec (3.7.0)
|
15
|
+
rspec-core (~> 3.7.0)
|
16
|
+
rspec-expectations (~> 3.7.0)
|
17
|
+
rspec-mocks (~> 3.7.0)
|
18
|
+
rspec-core (3.7.1)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-expectations (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-mocks (3.7.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.7.0)
|
26
|
+
rspec-support (3.7.1)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
benchmark-ips
|
33
|
+
bundler (~> 1.16)
|
34
|
+
fast_activesupport!
|
35
|
+
rake (~> 10.0)
|
36
|
+
rake-compiler
|
37
|
+
rspec (~> 3.0)
|
38
|
+
|
39
|
+
BUNDLED WITH
|
40
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Mehmet Emin INAC
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Fast Activesupport
|
2
|
+
|
3
|
+
> This project is built for FUN and not tested in production environment yet. It's been almost 7 years since I stopped writing C therefore these implementations may not be best ones in terms of performance and code quality. Also the behvaiours of the implementations may vary even especially for the error cases like passing the wrong type of argument.
|
4
|
+
|
5
|
+
ActiveSupport implemented in C from scratch for speeding it up.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'fast_activesupport'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install fast_activesupport
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
This gem overrides original ActiveSupport and changes it's methods with the ones written in C. The only thing you have to do is, placing this gem after `activesupport` or `rails` in your Gemfile.
|
26
|
+
|
27
|
+
## The list of improved modules/methods
|
28
|
+
|
29
|
+
Here is the list of modules and their methods migrated from Ruby to C along with performance improvements.
|
30
|
+
|
31
|
+
+ SecurityUtils
|
32
|
+
+ ::secure_compare (~4 times faster)
|
33
|
+
+ ::fixed_length_secure_compare (~6.5 times faster)
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/meinac/fast_activesupport.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require "rake/extensiontask"
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :default => [:compile, :spec]
|
8
|
+
|
9
|
+
Rake::ExtensionTask.new "fast_activesupport" do |ext|
|
10
|
+
ext.lib_dir = "lib/fast_activesupport"
|
11
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fast_activesupport"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <fast_activesupport_utils.h>
|
3
|
+
#include <security_utils.h>
|
4
|
+
|
5
|
+
static VALUE rb_is_fast(VALUE mod) {
|
6
|
+
return Qtrue;
|
7
|
+
}
|
8
|
+
|
9
|
+
static VALUE rb_fast_prefix(VALUE mod) {
|
10
|
+
return rb_str_new2(prefix());
|
11
|
+
}
|
12
|
+
|
13
|
+
void Init_fast_activesupport() {
|
14
|
+
VALUE active_support = rb_define_module("ActiveSupport");
|
15
|
+
|
16
|
+
rb_define_singleton_method(active_support, "is_fast?", rb_is_fast, 0);
|
17
|
+
rb_define_singleton_method(active_support, "fast_prefix", rb_fast_prefix, 0);
|
18
|
+
Init_security_utils();
|
19
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
const char *prefix() {
|
4
|
+
const char *prefix = getenv("FAST_PREFIX");
|
5
|
+
|
6
|
+
if(prefix == NULL) {
|
7
|
+
return "";
|
8
|
+
}
|
9
|
+
|
10
|
+
return prefix;
|
11
|
+
}
|
12
|
+
|
13
|
+
const char *method_name_for(const char *method_name) {
|
14
|
+
if(strlen(prefix()) == 0) {
|
15
|
+
return method_name;
|
16
|
+
}
|
17
|
+
|
18
|
+
char *new_method_name = malloc(strlen(method_name) + strlen(prefix()) + 2);
|
19
|
+
|
20
|
+
strcpy(new_method_name, prefix());
|
21
|
+
strcat(new_method_name, "_");
|
22
|
+
strcat(new_method_name, method_name);
|
23
|
+
|
24
|
+
return new_method_name;
|
25
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <fast_activesupport_utils.h>
|
3
|
+
|
4
|
+
static int fixed_length_secure_compare(VALUE a, VALUE b) {
|
5
|
+
long int a_length = RSTRING_LEN(a);
|
6
|
+
long int b_length = RSTRING_LEN(b);
|
7
|
+
|
8
|
+
if(a_length != b_length) {
|
9
|
+
rb_raise(rb_eArgError, "string length mismatch.");
|
10
|
+
}
|
11
|
+
|
12
|
+
char *a_string = RSTRING_PTR(a);
|
13
|
+
char *b_string = RSTRING_PTR(b);
|
14
|
+
|
15
|
+
int res = 0, i;
|
16
|
+
|
17
|
+
for(i = 0; i < a_length; i++) {
|
18
|
+
res = res | (a_string[i] ^ b_string[i]);
|
19
|
+
}
|
20
|
+
|
21
|
+
return !res;
|
22
|
+
}
|
23
|
+
|
24
|
+
static VALUE rb_fixed_length_secure_compare(VALUE self, VALUE a, VALUE b) {
|
25
|
+
Check_Type(a, T_STRING);
|
26
|
+
Check_Type(b, T_STRING);
|
27
|
+
|
28
|
+
return fixed_length_secure_compare(a, b) ? Qtrue : Qfalse;
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE rb_secure_compare(VALUE self, VALUE a, VALUE b) {
|
32
|
+
Check_Type(a, T_STRING);
|
33
|
+
Check_Type(b, T_STRING);
|
34
|
+
|
35
|
+
VALUE rb_mDigest = rb_path2class("Digest");
|
36
|
+
VALUE rb_sha256 = rb_const_get(rb_mDigest, rb_intern("SHA256"));
|
37
|
+
|
38
|
+
VALUE a_hex = rb_funcall(rb_sha256, rb_intern("hexdigest"), 1, a);
|
39
|
+
VALUE b_hex = rb_funcall(rb_sha256, rb_intern("hexdigest"), 1, b);
|
40
|
+
|
41
|
+
if(fixed_length_secure_compare(a_hex, b_hex)) {
|
42
|
+
return rb_funcall(a, rb_intern("=="), 1, b);
|
43
|
+
}
|
44
|
+
|
45
|
+
return Qfalse;
|
46
|
+
}
|
47
|
+
|
48
|
+
void Init_security_utils() {
|
49
|
+
rb_require("digest");
|
50
|
+
VALUE active_support = rb_define_module("ActiveSupport");
|
51
|
+
VALUE security_utils = rb_define_module_under(active_support, "SecurityUtils");
|
52
|
+
|
53
|
+
rb_define_method(security_utils, method_name_for("fixed_length_secure_compare"), rb_fixed_length_secure_compare, 2);
|
54
|
+
rb_funcall(security_utils, rb_intern("module_function"), 1, rb_str_new2(method_name_for("fixed_length_secure_compare")));
|
55
|
+
rb_define_method(security_utils, method_name_for("secure_compare"), rb_secure_compare, 2);
|
56
|
+
rb_funcall(security_utils, rb_intern("module_function"), 1, rb_str_new2(method_name_for("secure_compare")));
|
57
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
void Init_security_utils();
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "fast_activesupport/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fast_activesupport"
|
8
|
+
spec.version = FastActivesupport::VERSION
|
9
|
+
spec.authors = ["Mehmet Emin INAC"]
|
10
|
+
spec.email = ["mehmetemininac@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Active Support impelemented in C"
|
13
|
+
spec.description = "Active Support impelementation in C for the ones who need for speed."
|
14
|
+
spec.homepage = "https://github.com/meinac/fast_activesupport"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features|benchmarks)/})
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.extensions = %w[ext/fast_activesupport/extconf.rb]
|
22
|
+
spec.bindir = "bin"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rake-compiler"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "benchmark-ips"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast_activesupport
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mehmet Emin INAC
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: benchmark-ips
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Active Support impelementation in C for the ones who need for speed.
|
84
|
+
email:
|
85
|
+
- mehmetemininac@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions:
|
88
|
+
- ext/fast_activesupport/extconf.rb
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- ext/fast_activesupport/extconf.rb
|
102
|
+
- ext/fast_activesupport/fast_activesupport.c
|
103
|
+
- ext/fast_activesupport/fast_activesupport_utils.c
|
104
|
+
- ext/fast_activesupport/fast_activesupport_utils.h
|
105
|
+
- ext/fast_activesupport/security_utils.c
|
106
|
+
- ext/fast_activesupport/security_utils.h
|
107
|
+
- fast_activesupport.gemspec
|
108
|
+
- lib/fast_activesupport.rb
|
109
|
+
- lib/fast_activesupport/version.rb
|
110
|
+
homepage: https://github.com/meinac/fast_activesupport
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.7.3
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Active Support impelemented in C
|
134
|
+
test_files: []
|