forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit5cb0e33
committed
Speed up operations on numeric, mostly by avoiding palloc() overhead.
In many functions, a NumericVar was initialized from an input Numeric, to bepassed as input to a calculation function. When the NumericVar is notmodified, the digits array of the NumericVar can point directly to the digitsarray in the original Numeric, and we can avoid a palloc() and memcpy(). Addinit_var_from_num() function to initialize a var like that.Remove dscale argument from get_str_from_var(), as all the callers justpassed the dscale of the variable. That means that the rounding it used todo was not actually necessary, and get_str_from_var() no longer scribbles onits input. That makes it safer in general, and allows us to use the newinit_var_from_num() function in e.g numeric_out().Also modified numericvar_to_int8() to no scribble on its input either. Itcreates a temporary copy to avoid that. To compensate, the callers no longerneed to create a temporary copy, so the net # of pallocs is the same, but thisis nicer.In the passing, use a constant for the number 10 in get_str_from_var_sci(),when calculating 10^exponent. Saves a palloc() and some cycles to convertinteger 10 to numeric.Original patch by Kyotaro HORIGUCHI, with further changes by me. Reviewedby Pavel Stehule.1 parentb55743a commit5cb0e33
1 file changed
+104
-155
lines changed0 commit comments
Comments
(0)