xorcist 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -13
- data/ext/xorcist/xorcist.c +1 -1
- data/lib/xorcist/version.rb +1 -1
- metadata +6 -11
- data/ext/xorcist/Xorcist.java +0 -22
- data/ext/xorcist/XorcistService.java +0 -14
- data/test/refinements_test.rb +0 -23
- data/test/test_helper.rb +0 -11
- data/test/xorcist_test.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2de9dd2f8528b30b41521656e48ba9b4a1e5e39f
|
4
|
+
data.tar.gz: d791dcdd4766e8aef412047954e1504464ee6584
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9f69c450e68d80ca5cf76d32a72930ba8e3436ef1252ada6808eebc85273d4de805579a6f60a2c9e4924c514dd6ce653d5e9fc1c634f8c33c8a9e70f39ea611
|
7
|
+
data.tar.gz: 859066a86e1c7879f378d202adef1c179fba1f4d6f913ac4fcd161d575a4c2e86a2926745e0e8a13a0f153fba3d862a604cc03ea89742130c9c29b5cc4a4062c
|
data/README.md
CHANGED
@@ -11,8 +11,10 @@ Blazing-fast-cross-platform-monkey-patch-free string XOR. Yes, that means JRuby
|
|
11
11
|
require 'xorcist'
|
12
12
|
|
13
13
|
a, b = 'a', 'b'
|
14
|
-
Xorcist.xor(a, b)
|
15
|
-
|
14
|
+
Xorcist.xor(a, b) # => "\u0003"
|
15
|
+
a # => 'a'
|
16
|
+
Xorcist.xor!(a, b) # => "\u0003"
|
17
|
+
a # => "\u0003"
|
16
18
|
```
|
17
19
|
|
18
20
|
You can `include Xorcist` to expose its methods:
|
@@ -46,30 +48,35 @@ require 'xorcist/string_methods'
|
|
46
48
|
String.include(Xorcist::StringMethods)
|
47
49
|
```
|
48
50
|
|
51
|
+
## Encodings
|
52
|
+
|
53
|
+
Note the precise encoding `xor`'s output is undefined in the v1.0.x releases. In MRI `xor!` will return a string using your default encoding. With JRuby, `xor!` will return an ASCII-8BIT string.
|
54
|
+
|
49
55
|
## Benchmarks
|
50
56
|
|
51
|
-
Disclaimer: these are run from my craptop. Run 'em yourself with `bin/benchmark`.
|
57
|
+
Disclaimer: these are run from my craptop. Run 'em yourself with `bin/benchmark`. You'll need to have [`benchmark-ips`](https://github.com/evanphx/benchmark-ips) installed.
|
52
58
|
|
53
59
|
### MRI 2.2.1
|
54
60
|
|
55
61
|
```
|
56
62
|
Calculating -------------------------------------
|
57
|
-
ruby
|
58
|
-
xorcist
|
63
|
+
ruby 26.378k i/100ms
|
64
|
+
xorcist 73.291k i/100ms
|
59
65
|
-------------------------------------------------
|
60
|
-
ruby
|
61
|
-
xorcist 2.
|
66
|
+
ruby 376.513k (± 0.5%) i/s - 1.899M
|
67
|
+
xorcist 2.150M (± 3.9%) i/s - 10.774M
|
62
68
|
```
|
63
69
|
|
64
70
|
### JRuby 1.7.19
|
65
71
|
|
66
72
|
```
|
73
|
+
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
|
67
74
|
Calculating -------------------------------------
|
68
|
-
ruby
|
69
|
-
xorcist
|
75
|
+
ruby 31.795k i/100ms
|
76
|
+
xorcist 118.084k i/100ms
|
70
77
|
-------------------------------------------------
|
71
|
-
ruby
|
72
|
-
xorcist 3.
|
78
|
+
ruby 978.078k (±11.2%) i/s - 4.801M
|
79
|
+
xorcist 3.897M (±14.1%) i/s - 19.012M
|
73
80
|
```
|
74
81
|
|
75
82
|
## Installation
|
@@ -98,7 +105,8 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
98
105
|
|
99
106
|
## Special Thanks To...
|
100
107
|
|
101
|
-
- [Steve Sloan]
|
102
|
-
- [James Coglan]
|
108
|
+
- [Steve Sloan](http://www.finagle.org) for his [fast_xor gem](https://github.com/CodeMonkeySteve/fast_xor) from which most of the tests are borrowed
|
109
|
+
- [James Coglan](http://jcoglan.com) for his [guide on writing a JRuby Java extension](https://blog.jcoglan.com/2012/08/02/your-first-ruby-native-extension-java/)
|
110
|
+
- [Thomas Leitner](https://github.com/gettalong) for a faster pure Ruby XOR implementation that's used in the benchmark
|
103
111
|
- To all [contributers](https://github.com/fny/xorcist/graphs/contributors)! :beers:
|
104
112
|
|
data/ext/xorcist/xorcist.c
CHANGED
data/lib/xorcist/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xorcist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Faraz Yashar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rake-compiler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.9.5
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.9.5
|
69
69
|
description: Blazing-fast-cross-platform-monkey-patch-free string XOR. Yes, that means
|
70
70
|
JRuby too.
|
71
71
|
email:
|
@@ -76,17 +76,12 @@ extensions:
|
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
78
|
- README.md
|
79
|
-
- ext/xorcist/Xorcist.java
|
80
|
-
- ext/xorcist/XorcistService.java
|
81
79
|
- ext/xorcist/extconf.rb
|
82
80
|
- ext/xorcist/xorcist.c
|
83
81
|
- lib/xorcist.rb
|
84
82
|
- lib/xorcist/refinements.rb
|
85
83
|
- lib/xorcist/string_methods.rb
|
86
84
|
- lib/xorcist/version.rb
|
87
|
-
- test/refinements_test.rb
|
88
|
-
- test/test_helper.rb
|
89
|
-
- test/xorcist_test.rb
|
90
85
|
homepage: https://github.com/fny/xorcist
|
91
86
|
licenses:
|
92
87
|
- MIT
|
data/ext/xorcist/Xorcist.java
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
import org.jruby.anno.JRubyMethod;
|
2
|
-
import org.jruby.runtime.ThreadContext;
|
3
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
4
|
-
import org.jruby.RubyString;
|
5
|
-
import org.jruby.util.ByteList;
|
6
|
-
|
7
|
-
public class Xorcist {
|
8
|
-
@JRubyMethod(name = "xor!", module = true)
|
9
|
-
public static RubyString xorInPlace(ThreadContext context, IRubyObject self, RubyString x, RubyString y) {
|
10
|
-
byte[] xBytes = x.getBytes();
|
11
|
-
byte[] yBytes = y.getBytes();
|
12
|
-
|
13
|
-
int length = yBytes.length < xBytes.length ? yBytes.length : xBytes.length;
|
14
|
-
|
15
|
-
for(int i = 0; i < length; i++) {
|
16
|
-
xBytes[i] = (byte) (xBytes[i] ^ yBytes[i]);
|
17
|
-
}
|
18
|
-
|
19
|
-
x.setValue(new ByteList(xBytes));
|
20
|
-
return x;
|
21
|
-
}
|
22
|
-
}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import java.io.IOException;
|
2
|
-
|
3
|
-
import org.jruby.Ruby;
|
4
|
-
import org.jruby.RubyModule;
|
5
|
-
import org.jruby.runtime.load.BasicLibraryService;
|
6
|
-
|
7
|
-
public class XorcistService implements BasicLibraryService {
|
8
|
-
@Override
|
9
|
-
public boolean basicLoad(final Ruby runtime) throws IOException {
|
10
|
-
RubyModule xorcist = runtime.defineModule("Xorcist");
|
11
|
-
xorcist.defineAnnotatedMethods(Xorcist.class);
|
12
|
-
return true;
|
13
|
-
}
|
14
|
-
}
|
data/test/refinements_test.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
if RUBY_ENGINE != 'jruby' && RUBY_ENGINE != 'rbx' && RUBY_VERSION >= '2.0.0'
|
4
|
-
require 'xorcist/refinements'
|
5
|
-
|
6
|
-
class RefinementsTest < Minitest::Test
|
7
|
-
using Xorcist::Refinements
|
8
|
-
|
9
|
-
def test_xor
|
10
|
-
assert_equal ZERO, X.xor(X)
|
11
|
-
assert_equal ONE, X.xor(INVX)
|
12
|
-
assert_equal X, X.xor(ZERO)
|
13
|
-
assert_equal INVX, X.xor(ONE)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_xor_in_place
|
17
|
-
a = "String"
|
18
|
-
b = a
|
19
|
-
b.xor!(X)
|
20
|
-
assert_equal(a, b)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'xorcist'
|
2
|
-
|
3
|
-
require 'minitest'
|
4
|
-
require 'minitest/autorun'
|
5
|
-
require 'minitest/pride'
|
6
|
-
|
7
|
-
LEN = 16
|
8
|
-
ZERO = ([0x00].pack('C') * LEN).freeze
|
9
|
-
ONE = ([0xFF].pack('C') * LEN).freeze
|
10
|
-
X = (0...LEN).collect { rand 256 }.pack('C*').freeze
|
11
|
-
INVX = (0...LEN).collect { |i| X[i].ord ^ 0xFF }.pack('C*').freeze
|
data/test/xorcist_test.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class XorcistTest < Minitest::Test
|
4
|
-
include Xorcist
|
5
|
-
|
6
|
-
def test_xor
|
7
|
-
assert_equal ZERO, xor(X, X)
|
8
|
-
assert_equal ONE, xor(X, INVX)
|
9
|
-
assert_equal X, xor(X, ZERO)
|
10
|
-
assert_equal INVX, xor(X, ONE)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_xor_in_place
|
14
|
-
a = "String"
|
15
|
-
b = a
|
16
|
-
xor!(b, X)
|
17
|
-
assert_equal(a, b)
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
# Tests for different string storage behaviors in MRI.
|
22
|
-
# See http://patshaughnessy.net/2012/1/4/never-create-ruby-strings-longer-than-23-characters
|
23
|
-
# for details.
|
24
|
-
# Might as well run them in other Rubies too.
|
25
|
-
#
|
26
|
-
|
27
|
-
def test_embedded_string
|
28
|
-
a = "Embedded string"
|
29
|
-
assert a.size <= 23
|
30
|
-
b = a.dup
|
31
|
-
xor!(b, X)
|
32
|
-
refute_equal(a, b)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_heap_string
|
36
|
-
a = "A very long string that's stored on the heap"
|
37
|
-
assert a.size > 24
|
38
|
-
b = a.dup
|
39
|
-
xor!(b, X*2)
|
40
|
-
refute_equal(a, b)
|
41
|
-
end
|
42
|
-
end
|