nvs: avoid reading multiple times the same area
nvs: avoid reading multiple times the same area

The current NVS code checks for an empty ATE using th
_nvs_flash_cmp_const() function. This function loads the data and
compare them to a value. This means that when executed multiple on the
same area, the data get reloaded multiple time. This might have a
noticeable performance impact with an SPI flash.

Instead define a function _nvs_ate_cmp_const to compare an already read
struct nvs_ate with a constant value. Then replace the calls to
_nvs_flash_cmp_const() on struct nvs_ate by _nvs_flash_ate_rd() followed
by _nvs_ate_cmp_const(). This also has the advantage of explicitly
checking for errors instead of testing the error and the result of the
comparison at the same time.

Tested on a Nucleo L432KC board with the nvs sample. The maximum
initialization time (ie just before running the first garbage collector)
goes down to 6213 µs from 7350 µs.

Signed-off-by: Aurelien Jarno <bceb368e7f2cb351af47298f32034f0587bbe4a6@aurel32.net>

Vudentz/zephyr,ldts/zephyr,explora26/zephyr,punitvara/zephyr,Vudentz/zephyr,punitvara/zephyr,nashif/zephyr,finikorg/zephyr,galak/zephyr,ldts/zephyr,GiulianoFranchetto/zephyr,nashif/zephyr,nashif/zephyr,Vudentz/zephyr,zephyrproject-rtos/zephyr,finikorg/zephyr,GiulianoFranchetto/zephyr,galak/zephyr,zephyrproject-rtos/zephyr,zephyrproject-rtos/zephyr,punitvara/zephyr,zephyrproject-rtos/zephyr,finikorg/zephyr,galak/zephyr,galak/zephyr,nashif/zephyr,GiulianoFranchetto/zephyr,Vudentz/zephyr,explora26/zephyr,ldts/zephyr,GiulianoFranchetto/zephyr,zephyrproject-rtos/zephyr,ldts/zephyr,explora26/zephyr,galak/zephyr,explora26/zephyr,finikorg/zephyr,punitvara/zephyr,finikorg/zephyr,ldts/zephyr,explora26/zephyr,Vudentz/zephyr,punitvara/zephyr,nashif/zephyr,Vudentz/zephyr,GiulianoFranchetto/zephyr