Skip to content

Commit 2077971

Browse files
committed
(PUP-11841) Create mutable strings
In preparation for moving to frozen/immutable strings, explicitly create mutable strings in cases where we create a string buffer and append to it. There are multiple ways of creating a mutual string: ''.dup -'' String.new Although the latter is more verbose, I think it's better to be explicit.
1 parent 16977d9 commit 2077971

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+72
-72
lines changed

lib/puppet/application/doc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def rdoc
151151
end
152152

153153
def other
154-
text = ""
154+
text = String.new
155155
with_contents = options[:references].length <= 1
156156
exit_code = 0
157157
require_relative '../../puppet/util/reference'

lib/puppet/face/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
end
8282

8383
when_rendering :console do |to_be_rendered|
84-
output = ''
84+
output = String.new
8585
if to_be_rendered.keys.length > 1
8686
to_be_rendered.keys.sort.each do |setting|
8787
output << "#{setting} = #{to_be_rendered[setting]}\n"

lib/puppet/face/epp.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@
366366
end
367367

368368
def dump_parse(source, filename, options, show_filename = true)
369-
output = ""
369+
output = String.new
370370
evaluating_parser = Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new
371371
begin
372372
if options[:validate]
@@ -450,7 +450,7 @@ def render_inline(epp_source, compiler, options)
450450

451451
def render_file(epp_template_name, compiler, options, show_filename, file_nbr)
452452
template_args = get_values(compiler, options)
453-
output = ""
453+
output = String.new
454454
begin
455455
if show_filename && options[:header]
456456
output << "\n" unless file_nbr == 1

lib/puppet/face/module/list.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
environment = result[:environment]
7474
modules_by_path = result[:modules_by_path]
7575

76-
output = ''
76+
output = String.new
7777

7878
warn_unmet_dependencies(environment)
7979

@@ -247,7 +247,7 @@ def list_build_tree(list, ancestors=[], parent=nil, params={})
247247
# Returns a Hash
248248
#
249249
def list_build_node(mod, parent, params)
250-
str = ''
250+
str = String.new
251251
str << (mod.forge_name ? mod.forge_name.tr('/', '-') : mod.name)
252252
str << ' (' + colorize(:cyan, mod.version ? "v#{mod.version}" : '???') + ')'
253253

lib/puppet/face/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
end
174174

175175
def dump_parse(source, filename, options, show_filename = true)
176-
output = ""
176+
output = String.new
177177
evaluating_parser = Puppet::Pops::Parser::EvaluatingParser.new
178178
begin
179179
if options[:validate]

lib/puppet/ffi/windows/api_types.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def attach_function_private(*args)
2020

2121
class ::FFI::Pointer
2222
NULL_HANDLE = 0
23-
WCHAR_NULL = "\0\0".force_encoding('UTF-16LE').freeze
23+
WCHAR_NULL = String.new("\0\0").force_encoding('UTF-16LE').freeze
2424

2525
def self.from_string_to_wide_string(str, &block)
2626
str = Puppet::Util::Windows::String.wide_string(str)

lib/puppet/file_system/posix.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def binread(path)
1212
def compare_stream(path, stream)
1313
open(path, 0, 'rb') do |this|
1414
bsize = stream_blksize(this, stream)
15-
sa = "".force_encoding('ASCII-8BIT')
16-
sb = "".force_encoding('ASCII-8BIT')
15+
sa = String.new.force_encoding('ASCII-8BIT')
16+
sb = String.new.force_encoding('ASCII-8BIT')
1717
loop do
1818
this.read(bsize, sa)
1919
stream.read(bsize, sb)

lib/puppet/indirector/file_bucket_file/file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def list(request)
5757
end
5858
# Setting hash's default value to [], needed by the following loop
5959
bucket = Hash.new {[]}
60-
msg = ""
60+
msg = String.new
6161
# Get all files with mtime between 'from' and 'to'
6262
Pathname.new(request.options[:bucket_path]).find { |item|
6363
if item.file? and item.basename.to_s == "paths"

lib/puppet/indirector/indirection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def expiration
8080

8181
# Generate the full doc string.
8282
def doc
83-
text = ""
83+
text = String.new
8484

8585
text << scrub(@doc) << "\n\n" if @doc
8686

lib/puppet/module_tool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def self.is_module_root?(path)
6969
# Builds a formatted tree from a list of node hashes containing +:text+
7070
# and +:dependencies+ keys.
7171
def self.format_tree(nodes, level = 0)
72-
str = ''
72+
str = String.new
7373
nodes.each_with_index do |node, i|
7474
last_node = nodes.length - 1 == i
7575
deps = node[:dependencies] || []

0 commit comments

Comments
 (0)