-
Content Count
3586 -
Joined
-
Last visited
-
Days Won
176
Everything posted by David Heffernan
-
Micro optimization: use Pos before StringReplace
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
That's not the right way to solve this. The right way is to iterate over the string once rather than 5-10 times. Why would you want to iterate over the string so many times? -
It's really way easier in Python. Essentially a two liner, one to parse, and one to dump. That's how I'd do a one time conversion.
-
I don't know about you, but I use the best tool for the job, not the best tool written in Delphi!
-
Does anybody really see Dev C++ as being very useful these days? Unless I am mistaken, there are numerous IDEs now that far exceed what Dev C++ can do. Surely this is just a link about some work done on a legacy Delphi project. I can't believe the intent is to suggest that Dev C++ is relevant to C++ developers today.
-
I got bitten by an interface!
David Heffernan replied to Clément's topic in Algorithms, Data Structures and Class Design
Leaving aside the issues that are commented on by other, instead of if Supports(fBaseFrameClass, ISupportTask) then (fBaseFrame as ISupportTask).CheckTask; surely you need var Task: ISupportTask; ... if Supports(fBaseFrame, ISupportTask, Task) then Task.CheckTask; Two changes: Ask the implementing object rather than the class whether or not the interface is supported. Use the three argument overload of Supports so that you can get the interface while you are querying for it. -
Take some time to find/write helper functions to do the sort of processing you need on these byte arrays and your code may even end up easier to read!
-
AnsiString is no longer like an array of bytes because of the implicit encoding conversions that happen with that type. If you really have byte array data then perhaps a byte array is what you need.
-
Why are you using AnsiString at all? Why aren't you using the string type?
-
Trivial to do in Python. Read the YAML in, then dump to JSON. I'm assuming that this is a one time conversion. Because otherwise you'd use a YAML parser directly and wouldn't convert to JSON.
-
Micro optimization: use Pos before StringReplace
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
What Mike is concerned about is that calling Replace is slower than filtering with Pos before calling Replace. In reality he is asking the wrong question. The right solution to the problem (see five year old SO question) is to iterate over the input string once rather than 5-10 times. -
Micro optimization: use Pos before StringReplace
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
Well there's your problem! Run through the string once only and you'll get a huge boost in performance. I described how to do that in my comment to your Q. -
Micro optimization: use Pos before StringReplace
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
Why not achieve faster in all cases then? Does the code that you are looking at, that is a bottleneck, still call StringReplace multiple times per input string, as per the SO question? -
Micro optimization: use Pos before StringReplace
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
If the code is not a bottleneck then surely you'd reach the opposite conclusion. -
Micro optimization: use Pos before StringReplace
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
You really need to learn about the extract method refactoring. -
Micro optimization: use Pos before StringReplace
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
No. I'd consider writing one myself if I found that my program was spending a significant amount of time in an inefficient function. But we've had this discussion before and you don't believe in that approach. -
Micro optimization: use Pos before StringReplace
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
Nothing needs to be fixed. StringReplace is giving correct output, isn't it? You absolutely don't want to be calling Pos inside an efficient implementation of StringReplace. All that you are learning is that StringReplace is not efficiently written. The correct way to deal with that is to find/write and use a more efficient function to replace text. That is of course if this is a bottleneck in your code. Have you checked? BTW, do you really have calls to Pos littered through your code whenever you call StringReplace? -
Really? I mean true for bmp files but Windows API supports 32 bit bitmaps fine so far as I know.
-
Why don't you want to use a third party component?
-
Prevent External DLL from Exiting Application
David Heffernan replied to fjames's topic in Python4Delphi
That's what RPyC would gain you -
Hashing Street Addresses ?
David Heffernan replied to david_navigator's topic in Algorithms, Data Structures and Class Design
Two different values can have the same checksum. Read my previous post again. What you are expecting is impossible. I mean it. Impossible. -
Hashing Street Addresses ?
David Heffernan replied to david_navigator's topic in Algorithms, Data Structures and Class Design
What is a signature? All these terms being bandied about!! -
Hashing Street Addresses ?
David Heffernan replied to david_navigator's topic in Algorithms, Data Structures and Class Design
Yeah, that's not a hash. And what you want (known max length) is clearly impossible. If you could store arbitrary data in a lossless way in a data of a fixed length, then well, you can see where I am going. -
Hashing Street Addresses ?
David Heffernan replied to david_navigator's topic in Algorithms, Data Structures and Class Design
OK, maybe I misunderstood. I saw "hashing" and "indexed on", and inferred that you want to use a hashed collection like a dictionary. Hence the need to define data structure and what equality means. But perhaps you want to hash this data for some other reason. What will you do with this hash? -
Hashing Street Addresses ?
David Heffernan replied to david_navigator's topic in Algorithms, Data Structures and Class Design
First of all, don't worry about hashing the data. Work out how to represent the data, what data structure to use. And then define what you mean by equality for this data. Once you have done that, and have a clear specification of that, defining a hash function should be obvious. But if not, we will be able to help at that point. But first you need to define the data structure and the equality operator. -
Prevent External DLL from Exiting Application
David Heffernan replied to fjames's topic in Python4Delphi
Any code can terminate the process. The way you avoid this is to ensure that the code you run doesn't lead to fatal errors. In this case it sounds like the issue is that you need to make sure that your environment has the correct packages installed.