aviggiano / redis-roaring

Roaring Bitmaps for Redis
MIT License
348 stars 56 forks source link

Avoid creating empty bitmaps on R.BITOP command #12

Open aviggiano opened 7 years ago

aviggiano commented 7 years ago

The current implementation creates empty bitmaps for nonexistent source keys srckeys, which are then freed if necessary, since the API must be consistent with redis' native BITOP command.

    Bitmap* bitmap;
    if (srctype == REDISMODULE_KEYTYPE_EMPTY) {
      // "non-existent keys [...] are considered as a stream of zero bytes up to the length of the longest string"
      bitmap = bitmap_alloc();
      should_free[i] = true;
    }
    else {
      bitmap = RedisModule_ModuleTypeGetValue(srckey);
      should_free[i] = false;
    }
    bitmaps[i] = bitmap;

The presence of a should_free variable is specially disturbing, so I think we need to come up with something better.