View Issue Details

IDProjectCategoryView StatusLast Update
0030777FPCRTLpublic2017-03-15 23:02
ReporterBenito van der ZanderAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionfixed 
Product Version3.1.1Product Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0030777: inefficient string comparisons
Descriptionfpc_AnsiStr_Compare_equal:

is slow, because the temporary string variables lead to reference counting and an implicit exception block, even if these variables are not used.
The final else block should be moved to a different function.


CompareStr:

is slow, because it always compares the same string byte by byte.
There should be if pointer(s1) = pointer(s2) then exit(0)

Or if p1 = p2 then exit(0) in CompareMemRange

Is it supposed to ignore the encoding?
TagsNo tags attached.
Fixed in Revision35603
FPCOldBugId
FPCTarget
Attached Files

Activities

Thaddy de Koning

2016-10-24 11:14

reporter   ~0095308

Last edited: 2016-10-24 11:32

View 6 revisions

- You can turn off the exceptions with {$IMPLICITEXCEPTIONS OFF}
- Indeed, the same data with the same pointer can mean different things based on a chosen encoding.

Do you have a DWIM solution or proposal? ;)
But I guess that you may be right about a pointer check optimization given a known state with regards to the encoding..

In the case of strings with different encodings there is the small issue that they can be located at the same spot in memory yet mean totally different things even if the data is the same.
e.g. CP_1250 vs CP_1252 vs CP_1257.
In my case trying to negotiate between Dutch, English, Polish and Lithuanian.
My wife is Lithuanian.

Benito van der Zander

2016-10-24 12:48

reporter   ~0095311

> - You can turn off the exceptions with {$IMPLICITEXCEPTIONS OFF}

That is rarely helpful

It leaves the ref counting, which is also slow. And if you remove the ref counting, the exception handling is gone already.

> Do you have a DWIM solution or proposal? ;)

I am now using this: https://github.com/benibela/bbutils/blob/master/bbutils.pas#L2578-L2596

Thaddy de Koning

2016-10-24 13:59

reporter   ~0095317

Last edited: 2016-10-24 14:00

View 3 revisions

In your case it is: {$IMPLICITEXCEPTIONS OFF} which is meant to be used by experienced programmers like yourself.
But you made two cases in one and the same report and the second I second.

Sven Barth

2016-11-18 14:46

manager   ~0095998

@Thaddy: $IMPLICITEXCEPTIONS won't help with precompiled code in the RTL

Michael Van Canneyt

2017-03-15 23:02

administrator   ~0098938

Changed code as suggested.

Issue History

Date Modified Username Field Change
2016-10-23 17:42 Benito van der Zander New Issue
2016-10-24 11:14 Thaddy de Koning Note Added: 0095308
2016-10-24 11:16 Thaddy de Koning Note Edited: 0095308 View Revisions
2016-10-24 11:19 Thaddy de Koning Note Edited: 0095308 View Revisions
2016-10-24 11:20 Thaddy de Koning Note Edited: 0095308 View Revisions
2016-10-24 11:28 Thaddy de Koning Note Edited: 0095308 View Revisions
2016-10-24 11:32 Thaddy de Koning Note Edited: 0095308 View Revisions
2016-10-24 12:48 Benito van der Zander Note Added: 0095311
2016-10-24 13:59 Thaddy de Koning Note Added: 0095317
2016-10-24 14:00 Thaddy de Koning Note Edited: 0095317 View Revisions
2016-10-24 14:00 Thaddy de Koning Note Edited: 0095317 View Revisions
2016-11-18 14:46 Sven Barth Note Added: 0095998
2017-03-15 23:02 Michael Van Canneyt Fixed in Revision => 35603
2017-03-15 23:02 Michael Van Canneyt Note Added: 0098938
2017-03-15 23:02 Michael Van Canneyt Status new => resolved
2017-03-15 23:02 Michael Van Canneyt Fixed in Version => 3.1.1
2017-03-15 23:02 Michael Van Canneyt Resolution open => fixed
2017-03-15 23:02 Michael Van Canneyt Assigned To => Michael Van Canneyt
2017-03-15 23:02 Michael Van Canneyt Target Version => 3.2.0