My previous patch was committed \o/
My editor still had the file raceresults.cpp open and I found some ways to make it more simple & robust:
ReUpdateStandings() is used to read the existing results, update them with the most recent race's standings and write the updated results back. So basically you look for a driver, if he/she has previous results then add the points from the last race; if he/she does not have and previous results, create a record of it and put it between the results.
The original code went through the list of the recent race's results and sorted the array based on points with a bubble sort after each update. Now that it is luxury, sorting can be done after the updates have finished. That means we sort 1 time, not eg 20 times.
Then I thought - hey we are in the 21st century, let's not sort with a hand-written bubble sort when we have complete libraries for that. So I took a big breath and changed the array to a STL vector, then used STL sort() to handle sorting and find() to search for drivers. Result is: much simpler code. Oh and while I was there I changed the char* things to C++ strings, too.
I've sent the patch to Jean-Philippe, we'll see if he likes it or not. The patch can be applied to both trunk or sdl-port as the file is the same in both.
No comments:
Post a Comment