Repository: risingwavelabs/risingwave
File: src/storage/src/hummock/sstable/block.rs (Rust)

Code before:
        }
        #[cfg(debug_assertions)]
        self.debug_valid();

        // Call the core implementation with the pre-encoded key
        self.add_encoded_impl(encoded_key_without_table_id, value);
    }

    pub fn add_for_test(&mut self, full_key: FullKey<&[u8]>, value: &[u8]) {
        let input_table_id = full_key.user_key.table_id;
        match self.table_id {
            Some(current_table_id) => assert_eq!(current_table_id, input_table_id),
            None => self.table_id = Some(input_table_id),
        }
        #[cfg(debug_assertions)]
        self.debug_valid();

        let mut key: BytesMut = Default::default();
        full_key.encode_into_without_table_id(&mut key);

        // Call the core implementation with encoded key
        self.add_encoded_impl(&key, value);
    }

    /// Core implementation that accepts pre-encoded key.
    /// This is used by both `add` and `add_encoded` to avoid code duplication.
    fn add_encoded_impl(&mut self, key: &[u8], value: &[u8]) {
        if self.entry_count > 0 {
            debug_assert!(!key.is_empty());
            debug_assert_eq!(
                KeyComparator::compare_encoded_full_key(&self.last_key[..], key),
                Ordering::Less,
            );
        }
        // Update restart point if needed and calculate diff key.
        let k_type = LenType::new(key.len());
        let v_type = LenType::new(value.len());

        let type_mismatch = if let Some(RestartPoint {
            offset: _,
            key_len_type: last_key_len_type,
            value_len_type: last_value_len_type,
        }) = self.restart_points_type_index.last()
        {
            k_type != *last_key_len_type || v_type != *last_value_len_type
        } else {
            true
        };

        let diff_key = if self.entry_count.is_multiple_of(self.restart_count) || type_mismatch {
            let offset = utils::checked_into_u32(self.buf.len()).unwrap_or_else(|_| {

Review comment (suggestion):
The comment references a method named `add_encoded`, but there is no such method in the code. The method is actually called `add_for_test`. Update the comment to reference `add_for_test` instead of `add_encoded` for accuracy.
```suggestion
    /// This is used by both `add` and `add_for_test` to avoid code duplication.
```

Code after:
        }
        #[cfg(debug_assertions)]
        self.debug_valid();

        // Call the core implementation with the pre-encoded key
        self.add_encoded_impl(encoded_key_without_table_id, value);
    }

    #[cfg(any(test, feature = "test"))]
    pub fn add_for_test(&mut self, full_key: FullKey<&[u8]>, value: &[u8]) {
        let input_table_id = full_key.user_key.table_id;
        match self.table_id {
            Some(current_table_id) => assert_eq!(current_table_id, input_table_id),
            None => self.table_id = Some(input_table_id),
        }
        #[cfg(debug_assertions)]
        self.debug_valid();

        let mut key: BytesMut = Default::default();
        full_key.encode_into(&mut key);

        // Slice off the table_id prefix to get the key without table_id
        let encoded_key_without_table_id = &key[TABLE_PREFIX_LEN..];

        // Call the core implementation with encoded key
        self.add_encoded_impl(encoded_key_without_table_id, value);
    }

    /// Core implementation that accepts pre-encoded key.
    /// This is used by both `add` and `add_for_test` to avoid code duplication.
    fn add_encoded_impl(&mut self, key: &[u8], value: &[u8]) {
        if self.entry_count > 0 {
            debug_assert!(!key.is_empty());
            debug_assert_eq!(
                KeyComparator::compare_encoded_full_key(&self.last_key[..], key),
                Ordering::Less,
            );
        }
        // Update restart point if needed and calculate diff key.
        let k_type = LenType::new(key.len());
        let v_type = LenType::new(value.len());

        let type_mismatch = if let Some(RestartPoint {
            offset: _,
            key_len_type: last_key_len_type,
            value_len_type: last_value_len_type,
        }) = self.restart_points_type_index.last()
        {
            k_type != *last_key_len_type || v_type != *last_value_len_type
        } else {
            true