Re: Fastcode Trim B&V 0.3.0



Hi Anders,

But why make a rule about it?

For the same reason why we also measure address space consumption in the
memory manager challenge . If memory usage is not discussed in most other
challenges it is because it is the same for all implementations. The two
most important performance metrics for me are speed and memory usage.

Also, note that by returning the same string (with incremented refcount)
you're breaking the current Trim() 'contract' - "Trim() returns a unique
string" - probably not spelled out anywhere, but implied by the code.

There is such a contract for SetLength according to the documentation, but I
have not seen such a claim for Trim.

Some code somewhere may today use that fact - maybe *that's* the rule that
should be enforced? Has the VCL been checked that no such assumption is
made anywhere there? The JCL? JVCL? Other important libraries?

Relying on undocumented implementation details is dangerous and usually poor
programming practice. I doubt any code in the JCL would do that
unnecessarily, such as in the case of Trim.

The scenario in which the fact that trim does not return a unique string
will affect you is if you do low level hacking of the string data, in which
case you should know better than to make such an assumption. Note that if
you cast a string to pchar or change a character by index, that the compiler
will insert a call to UniqueString anyway.

FWIW I have been running such a modified Trim for a long time (and it seems
Robert has too) and I have never had any issues with any 3rd party code.

Regards,
Pierre


.



Relevant Pages

  • Re: Fastcode Trim B&V 0.3.0
    ... returns a unique string" - probably not spelled out anywhere, ... Any code that modifies the string itself with non-string operations. ... that the RTL Trim() has this undocumented 'contract' (quite obvious by code ...
    (borland.public.delphi.language.basm)
  • Re: Fortran
    ... it didn't implement a working TRIM() in F77. ... CHARACTER*80 STRING ... EXTERNAL MYTRIM ... STRING = 'alongword' ...
    (comp.lang.fortran)
  • Re: Fortran
    ... it didn't implement a working TRIM() in F77. ... CHARACTER*10 MYTRIM ... STRING = 'hello' ... STRING = 'alongword' ...
    (comp.lang.fortran)
  • Trim() function chain-link. Please Help me...
    ... income dependent on the number in the household. ... that is I used the Trim() function... ... wrong that is preventing my string of codes to not recognize the other ... then move result to Cell C53 ...
    (microsoft.public.excel.programming)
  • Re: FAQ Topic - How do I trim whitespace - trim/trimRight/trimLeft (2007-12-25)
    ... though the Subject refers to whitespace the answer refers only to ... the word used alone is thus not ideal for describing what trim ... Most string manipulations are best done by using Regular Expressions. ...
    (comp.lang.javascript)