/* If the allocated heap size is >= 3*used and 2*used >= KEVENTS_EXTEND_COUNT, reduce it to 2*used.  */
void kevents_reduce(kevents *kv)
/* If the allocated heap size is >= 3*used and 2*used >= KEVENTS_EXTEND_COUNT, reduce it to 2*used.  */
void kevents_reduce(kevents *kv)
{
  g_assert (kv != NULL);
  gsize candidate_sz;
  if (kv->kq_size == 0 || kv->kq_allocated == 0 || kv->memory == NULL)
    return;
  candidate_sz = 2 * kv->kq_size;
  if (((double) kv->kq_allocated / kv->kq_size) >= 3 &&
      candidate_sz >= KEVENTS_EXTEND_COUNT)
    {
      kv->kq_allocated = candidate_sz;
      kv->memory = g_renew (struct kevent, kv->memory, kv->kq_allocated);
    }
}