Hello Francesco, hello all, > On 27 February 2018 at 22:48 Francesco Pretto <cez...@gmail.com> wrote: > > > On 27 February 2018 at 22:22, Matthew Brincke <ma...@mailbox.org> wrote: > > I'd like > > to make its code more C++-like by removing those > > and replacing them with dynamic_cast. > > My opinion: dynamic_cast has a runtime performance cost and should be > done when it is desired to test the type hierarchy at runtime, for > example when doing conditional code based on types. Most of the time, AIUI many PdfVariant methods are doing just that: checking whether a downcast, that is, to a more specific type, i.e. subtype, is safe, by using a enum field in a struct, then if it isn't, throw an exception, otherwise doing the cast.
> C/C++ developer are perfectly aware of the safeness of the casts they > are doing, and they do C style casts or C++ static casts, getting a > performance advantage over doing dynamic_cast everywhere. Since C/C++ > are languages where developers are supposed to be more aware of the > consequences of their choices, I would rather prefer keeping C/C++ > static casts instead of blindly convert of all them to dynamic_cast. I found a stackoverflow.com answer (very highly upvoted) [1] where it says static_cast can be used "as long as it doesn't cast through virtual inheritance", so I have to check if PdfVariant uses that. > There are a lot of other places where I would invest time in improving > the code, such as 32/64 bits API determinism (this was discussed > today) or optimizations (removing double lookups from dictionaries). Agreed. Best regards, mabri [1] https://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-and-reinterpret-cast-be-used ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users