Optimize perm_begin and perm_end
[Issue#] SSDWSSP-596
[Bug/Feature] Database operations executed in perm_begin and perm_end
are very slow.
[Cause] All the rules were calculated every perm_end.
[Solution] Calculate only modified rules.
[Verification] Build, install, run tests - to check correctness.
Compare speed of application installation and
deinstallation before and after library update.
Make sure a database is exactly the same as in new
image (running our tests adds a lot of new rules).
I've notices 2x - 7x speedup (depending on the number of
modified rules).
Change-Id: Ifba86c1c8b09230458482c9c31468245bf3edbbb