4949import org .jruby .anno .JRubyClass ;
5050import org .jruby .anno .JRubyMethod ;
5151import org .jruby .ast .util .ArgsUtil ;
52- import org .jruby .common .IRubyWarnings .ID ;
5352import org .jruby .exceptions .RaiseException ;
5453import org .jruby .runtime .ThreadContext ;
5554import org .jruby .runtime .builtin .IRubyObject ;
@@ -83,24 +82,23 @@ public class RubyStringScanner extends RubyObject {
8382
8483 public static RubyClass createScannerClass (final Ruby runtime ) {
8584 RubyClass Object = runtime .getObject ();
86- ThreadContext context = runtime .getCurrentContext ();
8785
8886 RubyClass scannerClass = runtime .defineClass ("StringScanner" , Object , RubyStringScanner ::new );
8987
9088 RubyClass standardError = runtime .getStandardError ();
91- RubyClass error = scannerClass .defineClassUnder (context , "Error" , standardError , standardError .getAllocator ());
92- if (!Object .isConstantDefined (context , "ScanError" )) {
93- Object .defineConstant (context , "ScanError" , error );
94- Object .deprecateConstant (context , "ScanError" );
89+ RubyClass error = scannerClass .defineClassUnder ("Error" , standardError , standardError .getAllocator ());
90+ if (!Object .isConstantDefined ("ScanError" , true )) {
91+ Object .defineConstant ("ScanError" , error );
92+ Object .deprecateConstant (runtime , "ScanError" );
9593 }
9694
9795 RubyString version = runtime .newString (STRSCAN_VERSION );
9896 version .setFrozen (true );
99- scannerClass .setConstant (context , "Version" , version );
97+ scannerClass .setConstant ("Version" , version );
10098 RubyString id = runtime .newString ("$Id$" );
10199 id .setFrozen (true );
102- scannerClass .setConstant (context , "Id" , id );
103- scannerClass .deprecateConstant (context , "Id" );
100+ scannerClass .setConstant ("Id" , id );
101+ scannerClass .deprecateConstant (runtime , "Id" );
104102
105103 scannerClass .defineAnnotatedMethods (RubyStringScanner .class );
106104
@@ -186,7 +184,7 @@ public IRubyObject reset(ThreadContext context) {
186184 @ JRubyMethod (name = "terminate" )
187185 public IRubyObject terminate (ThreadContext context ) {
188186 check (context );
189- curr = str .getByteList (). getRealSize ();
187+ curr = str .size ();
190188 clearMatchStatus ();
191189 return this ;
192190 }
@@ -224,7 +222,7 @@ public IRubyObject set_pos(ThreadContext context, IRubyObject pos) {
224222 Ruby runtime = context .runtime ;
225223
226224 int i = RubyNumeric .num2int (pos );
227- int size = str .getByteList (). getRealSize ();
225+ int size = str .size ();
228226 if (i < 0 ) i += size ;
229227 if (i < 0 || i > size ) throw runtime .newRangeError ("index out of range." );
230228 this .curr = i ;
@@ -243,8 +241,7 @@ public IRubyObject charpos(ThreadContext context) {
243241 }
244242
245243 private IRubyObject extractRange (Ruby runtime , int beg , int end ) {
246- ByteList byteList = str .getByteList ();
247- int size = byteList .getRealSize ();
244+ int size = str .size ();
248245
249246 if (beg > size ) return runtime .getNil ();
250247 if (end > size ) end = size ;
@@ -255,7 +252,7 @@ private IRubyObject extractRange(Ruby runtime, int beg, int end) {
255252 private IRubyObject extractBegLen (Ruby runtime , int beg , int len ) {
256253 assert len >= 0 ;
257254
258- int size = str .getByteList (). getRealSize ();
255+ int size = str .size ();
259256
260257 if (beg > size ) return runtime .getNil ();
261258 len = Math .min (len , size - beg );
@@ -297,7 +294,7 @@ private IRubyObject scan(ThreadContext context, IRubyObject regex, boolean succp
297294 regs = matchRegion ;
298295 }
299296
300- if (ret == -2 ) {
297+ if (ret == -2 ) {
301298 throw runtime .newRaiseException ((RubyClass ) getMetaClass ().getConstant ("ScanError" ), "regexp buffer overflow" );
302299 }
303300 if (ret < 0 ) return context .nil ;
@@ -356,10 +353,6 @@ private void succ() {
356353 }
357354 }
358355
359- private int currPtr () {
360- return str .getByteList ().getBegin () + curr ;
361- }
362-
363356 private int matchTarget () {
364357 if (fixedAnchor ) {
365358 return str .getByteList ().getBegin ();
@@ -484,7 +477,7 @@ public IRubyObject getchCommon(ThreadContext context) {
484477 public IRubyObject get_byte (ThreadContext context ) {
485478 check (context );
486479 clearMatchStatus ();
487- if (curr >= str .getByteList (). getRealSize ()) return context .nil ;
480+ if (curr >= str .size ()) return context .nil ;
488481
489482 prev = curr ;
490483 curr ++;
@@ -761,8 +754,7 @@ public IRubyObject rest(ThreadContext context) {
761754 check (context );
762755 Ruby runtime = context .runtime ;
763756
764- ByteList value = str .getByteList ();
765- int realSize = value .getRealSize ();
757+ int realSize = str .size ();
766758
767759 if (curr >= realSize ) {
768760 return RubyString .newEmptyString (runtime , str .getEncoding ());
0 commit comments