Project

General

Profile

Actions

Feature #905

closed

Add String.new(fixnum) to preallocate large buffer

Added by headius (Charles Nutter) almost 16 years ago. Updated over 8 years ago.

Status:
Closed
Target version:
-
[ruby-core:20668]

Description

=begin
Because Strings are used in ruby as arbitrary byte buffers, and because the cost of growing a String increases as it gets larger (especially when it starts small), String.new should support a form that takes a fixnum and ensures the backing store will have at least that much room. This is analogous to Array.new(fixnum) which does the same thing.

The simple implementation of this would just add a Fixnum check to the String.new method, and the result would be an empty string with that size buffer. This would allow heavy string-appending algorithms and libraries (like ERb) to avoid doing so many memory copies while they run.
=end


Files

string_buffer.diff (846 Bytes) string_buffer.diff String#buffer murphy (Kornelius Kalnbach), 03/06/2010 11:49 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #12024: Add String.buffer, for creating strings with large capacitiesClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0