[^yann] minor performance
(cherry picked from commit 9f29741)
[yann] getContexts(): avoid costly LOG.assertTrue
(cherry picked from commit 9e97ce6)