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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 793234244f107edb7c72b40c9781eb02e9764a57
4
- data.tar.gz: aeeaf63a70d085e9900d4023feb461b2e8a13518
3
+ metadata.gz: 2de9dd2f8528b30b41521656e48ba9b4a1e5e39f
4
+ data.tar.gz: d791dcdd4766e8aef412047954e1504464ee6584
5
5
  SHA512:
6
- metadata.gz: dbf415060c191c8cca73230f9e78af36ef5a8e1e14fb3adb777ca8fd86fc18d590666ab2187356bd4b7d6d6394babbea90979302581d8ecd2453a27d48a0bdb1
7
- data.tar.gz: bbe34eed87957f7144e5962330d42ffcc611927f353075d09854670accef29fc26a563b9e8125abb631b9c1ca184089d6d43343bf2e37fb4f3956c65cd4508c7
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
- Xorcist.xor!(a, b)
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 11.136k i/100ms
58
- xorcist 71.472k i/100ms
63
+ ruby 26.378k i/100ms
64
+ xorcist 73.291k i/100ms
59
65
  -------------------------------------------------
60
- ruby 144.198k1.3%) i/s - 723.840k
61
- xorcist 2.155M0.7%) i/s - 10.792M
66
+ ruby 376.513k0.5%) i/s - 1.899M
67
+ xorcist 2.150M3.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 142.000 i/100ms
69
- xorcist 88.006k i/100ms
75
+ ruby 31.795k i/100ms
76
+ xorcist 118.084k i/100ms
70
77
  -------------------------------------------------
71
- ruby 3.113k32.6%) i/s - 11.218k in 5.781000s
72
- xorcist 3.184M32.9%) i/s - 12.321M
78
+ ruby 978.078k11.2%) i/s - 4.801M
79
+ xorcist 3.897M14.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][http://www.finagle.org] for his [fast_xor gem][https://github.com/CodeMonkeySteve/fast_xor] from which most of the tests are borrowed
102
- - [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/]
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
 
@@ -1,4 +1,4 @@
1
- #include "ruby.h"
1
+ #include <ruby.h>
2
2
 
3
3
  VALUE Xorcist = Qnil;
4
4
 
@@ -1,3 +1,3 @@
1
1
  module Xorcist
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
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.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-07-13 00:00:00.000000000 Z
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: '0'
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: '0'
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
@@ -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
- }
@@ -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