If you remove or comment out the 2 lines after the # clean up comment it leaves the array modified line with the x dimension being the length of the curve after running the script. Seems there is no need to apply the modifier… which is handy as its one of those things i’m not sure how to do without context.
Also I concur with your comment re curve length is used in several places in blender … fit_curve being one of them.
If you add a curve modifier to it you will see its a pretty good copy of the curve… the smaller the bits the more accurate.