Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7ad158d

Browse files
committed
Add a jruby/core_ext for String.alloc, to preallocate a larger buffer size.
1 parent ea68cbd commit 7ad158d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/org/jruby/RubyJRuby.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public static RubyModule createJRubyExt(Ruby runtime) {
9696
public static void createJRubyCoreExt(Ruby runtime) {
9797
runtime.getClassClass().defineAnnotatedMethods(JRubyClassExtensions.class);
9898
runtime.getThread().defineAnnotatedMethods(JRubyThreadExtensions.class);
99+
runtime.getString().defineAnnotatedMethods(JRubyStringExtensions.class);
99100
}
100101

101102
public static class ExtLibrary implements Library {
@@ -350,6 +351,13 @@ public static IRubyObject times(IRubyObject recv, Block unusedBlock) {
350351
}
351352
}
352353

354+
public static class JRubyStringExtensions {
355+
@JRubyMethod(name = "alloc", meta = true)
356+
public static IRubyObject alloc(ThreadContext context, IRubyObject recv, IRubyObject size) {
357+
return RubyString.newStringLight(context.getRuntime(), (int)size.convertToInteger().getLongValue());
358+
}
359+
}
360+
353361
public static class MethodExtensions {
354362
@JRubyMethod(name = "args")
355363
public static IRubyObject methodArgs(IRubyObject recv) {

0 commit comments

Comments
 (0)