fast_blank_java 0.0.1-java → 0.0.2-java

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: 505346efda3547f6c25c1c73173db392936ebdb7
4
- data.tar.gz: 0a1242135e7dbf0b603cf767e4411e73cc7f5d0d
3
+ metadata.gz: ec3dd8b44c891aa2b6e87b0abd1be712c085cac3
4
+ data.tar.gz: 44081f90b324b6d020c3daadebe9bb3f88fed5cd
5
5
  SHA512:
6
- metadata.gz: fafaabc6a8297cf87309a3308c264f02e1e933949881d126143367e7db986e095c6e9adb564f431c1d9aff2b8910a045c69ad07efb0d9a420177ec942466c9bb
7
- data.tar.gz: 3d57b29a8c114049db6d8d2df42317a2907387bb3a9b56bd0b6d15c6bed6b162b1b78ddc01935bd189b255a0cbdef093d871d381c0def6132e503d17f5fb8b1b
6
+ metadata.gz: 8ce4f876e96a59390d7934ce128d1d9a548ae52dfc6a80f7a144d4124d44109aba8be49c2d1729e8d765dd87e330579af154556d2f886c108ec6648aef524ac8
7
+ data.tar.gz: 4d41f078e365f4d4533936e5ad4d3808ef46d032f798d5cc8d686207fc0bb44a70faf8bd2fbc1c4b8bcbb31163d7aa5baadcf24bdcc36b214652de50d2b84722
@@ -25,9 +25,8 @@ test_strings = [
25
25
  ]
26
26
 
27
27
  test_strings.each do |s|
28
- raise "failed on #{s.inspect}" if s.blank? != s.slow_blank?
29
- raise "failed on #{s.inspect}" if s.blank? != s.new_slow_blank?
30
- raise "failed on #{s.inspect}" if s.blank? != s.fast_blank_java?
28
+ raise "failed on #{s.inspect} blank? => #{s.blank?} : slow_blank? => #{s.slow_blank?}" if s.blank? != s.slow_blank?
29
+ raise "failed on #{s.inspect} blank? => #{s.blank?} : new_slow_blank? => #{s.new_slow_blank?}" if s.blank? != s.new_slow_blank?
31
30
  end
32
31
 
33
32
  test_strings.each do |s|
@@ -36,7 +35,15 @@ test_strings.each do |s|
36
35
  x.report("Fast Blank Java") do |times|
37
36
  i = 0
38
37
  while i < times
39
- s.fast_blank_java?
38
+ s.blank?
39
+ i += 1
40
+ end
41
+ end
42
+
43
+ x.report("Fast Blank Java AS") do |times|
44
+ i = 0
45
+ while i < times
46
+ s.fast_blank_java_as?
40
47
  i += 1
41
48
  end
42
49
  end
@@ -16,14 +16,12 @@ import org.jruby.runtime.ThreadContext;
16
16
  import org.jruby.runtime.builtin.IRubyObject;
17
17
 
18
18
  public class FastBlankJava {
19
- @JRubyMethod(name = { "fast_blank_java?", "blank?" })
19
+ @JRubyMethod(name = { "fast_blank_java_as?", "blank_as?" })
20
20
  public static IRubyObject fast_blank_as_java_p(ThreadContext context, IRubyObject self) {
21
- org.jruby.Ruby runtime = context.getRuntime();
22
-
23
21
  if (self instanceof RubyString) {
24
22
  org.jruby.RubyString rubyString = ((RubyString) self);
25
23
  if (rubyString.isEmpty()) {
26
- return runtime.getTrue();
24
+ return context.tru;
27
25
  }
28
26
 
29
27
  ByteList blankValue = rubyString.getByteList();
@@ -67,15 +65,45 @@ public class FastBlankJava {
67
65
  case 0x3000:
68
66
  break;
69
67
  default:
70
- return runtime.getFalse();
68
+ return context.fals;
71
69
  }
72
70
 
73
71
  next_char += len_p[0];
74
72
  }
75
73
 
76
- return runtime.getTrue();
74
+ return context.tru;
77
75
  }
78
76
 
79
77
  throw context.getRuntime().newTypeError("can't #fast_blank_java? a non-string object");
80
78
  }
79
+
80
+ public static boolean rb_isspace(int character) {
81
+ return character == ' ' || ('\t' <= character && character <= '\r');
82
+ }
83
+
84
+ @JRubyMethod(name = { "fast_blank_java?", "blank?" })
85
+ public static IRubyObject fast_blank_p(ThreadContext context, IRubyObject self) {
86
+ Encoding enc;
87
+ int s, e;
88
+ byte[] sBytes;
89
+ Ruby runtime = context.runtime;
90
+ RubyString str = (RubyString) self;
91
+ enc = str.getEncoding();
92
+ ByteList sByteList = str.getByteList();
93
+ sBytes = sByteList.unsafeBytes();
94
+ s = sByteList.begin();
95
+ if (str.size() == 0) return context.tru;
96
+ e = s + sByteList.realSize();
97
+ int[] n = {0};
98
+ int cc = 0;
99
+
100
+ while (s < e) {
101
+ cc = EncodingUtils.encCodepointLength(runtime, sBytes, s, e, n, enc);
102
+ if (!rb_isspace(cc) && cc != 0) { return context.fals; }
103
+
104
+ s += n[0];
105
+ }
106
+
107
+ return context.tru;
108
+ }
81
109
  }
@@ -10,10 +10,8 @@ import java.io.IOException;
10
10
  public class FastBlankJavaService implements BasicLibraryService {
11
11
  @Override
12
12
  public boolean basicLoad(final Ruby runtime) throws IOException {
13
- RubyModule protobuf_java_helpers = runtime.getModule("FastBlankJava");
14
-
15
- RubyModule varinter = protobuf_java_helpers.defineModuleUnder(FastBlankJava.class.getSimpleName());
16
- varinter.defineAnnotatedMethods(FastBlankJava.class);
13
+ RubyModule fast_blank_java = runtime.getModule("FastBlankJava");
14
+ fast_blank_java.defineAnnotatedMethods(FastBlankJava.class);
17
15
 
18
16
  return true;
19
17
  }
@@ -10,5 +10,5 @@ require "jars/fast_blank_java.jar"
10
10
  com.abrandoned.fast_blank_java.FastBlankJavaService.new.basicLoad(::JRuby.runtime)
11
11
 
12
12
  class String
13
- include ::FastBlankJava::FastBlankJava
13
+ include ::FastBlankJava
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module FastBlankJava
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_blank_java
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: java
6
6
  authors:
7
7
  - Brandon Dewitt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-26 00:00:00.000000000 Z
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement