Re: StringBuffer/StringBuilder efficiency



On Sat, 26 Sep 2009, Patricia Shanahan wrote:

Tom Anderson wrote:
...
Oh, and you could make it a List<CharSequence>, and only toString things if they aren't instanceof CharSequence. The main effect of that is that you can append things like StringBuffers and CharBuffers directly, without having to toString them.
...

Doing that would need to be very carefully documented, and lead to inconsistent behavior. Appending something that is not a CharSequence would capture its toString() result as of the time of the append. Appending a CharSequence would capture its toString() as of the time of extraction of the concatenated string.

Ah yes, very good point!

If this was python, i'd think about modifying appended StringBuilders at runtime to intercept any attempts to modify them, to run a hook which would copy the original contents to a string for appending purposes before removing the interception code and carrying on with the append, but fortunately, such madness is not possible in java.

tom

--
Don't believe his lies.
.



Relevant Pages

  • Re: Parsing / " characters
    ... have the rest of the code to append the ... - JCL inserts that string at the start of every program, ... >>the code associated with that program - in exact order, ... >>Dim db As Database, tdf As TableDef ...
    (microsoft.public.access.externaldata)
  • Re: Making static class ToString() not possible, why?
    ... Yes, of course, those are OOP things, and a static class is basically ... invoked when you append "it" to a string, but with a static class there ... ToString(), into a static class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Parsing / " characters
    ... create a new record in table TTT containing the string ... >I can append ALL the records from the ... >Dim db As Database, tdf As TableDef ... >> Dim lngFN as Long ...
    (microsoft.public.access.externaldata)
  • Re: Fastest way to append text to a TextBox
    ... What's the fastest way to append text to a TextBox? ... CPU and, even if I limit the TextBox to just 30KB of text, it takes over ... Private Sub AppendText(ByVal sText As String) ... Dim iLen As Integer = .Text.Length + sText.Length ...
    (microsoft.public.dotnet.languages.vb)
  • RE: SaveWorkbookAsToday()
    ... Create a string variables for the day and convert your date to the format you ... Then append or concatenate the string date where necessary in the file name. ... Dim DateFormat As String ...
    (microsoft.public.excel.programming)