Repository: apache/arrow
File: c_glib/arrow-glib/compute.cpp (C++)

Code before:
    g_free(priv->replacement);
    priv->replacement = nullptr;
  }
  G_OBJECT_CLASS(garrow_replace_substring_options_parent_class)->dispose(object);
}

static void
garrow_replace_substring_options_set_property(GObject *object,
                                              guint prop_id,
                                              const GValue *value,
                                              GParamSpec *pspec)
{
  auto options =
    garrow_replace_substring_options_get_raw(GARROW_REPLACE_SUBSTRING_OPTIONS(object));
  auto priv = GARROW_REPLACE_SUBSTRING_OPTIONS_GET_PRIVATE(object);

  switch (prop_id) {
  case PROP_REPLACE_SUBSTRING_OPTIONS_PATTERN:
    {
      const gchar *pattern = g_value_get_string(value);
      if (priv->pattern) {
        g_free(priv->pattern);
      }
      priv->pattern = g_strdup(pattern);
      options->pattern = pattern ? pattern : "";
    }
    break;
  case PROP_REPLACE_SUBSTRING_OPTIONS_REPLACEMENT:
    {
      const gchar *replacement = g_value_get_string(value);
      if (priv->replacement) {
        g_free(priv->replacement);
      }
      priv->replacement = g_strdup(replacement);
      options->replacement = replacement ? replacement : "";
    }
    break;
  case PROP_REPLACE_SUBSTRING_OPTIONS_MAX_REPLACEMENTS:
    options->max_replacements = g_value_get_int64(value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    break;
  }
}

static void
garrow_replace_substring_options_get_property(GObject *object,
                                              guint prop_id,
                                              GValue *value,
                                              GParamSpec *pspec)

Review comment (refactor):
Can we simplify this?

```suggestion
    options->pattern = g_value_get_string(value);
```

Code after:
enum {
  PROP_EXTRACT_REGEX_OPTIONS_PATTERN = 1,
};

G_DEFINE_TYPE(GArrowExtractRegexOptions,
              garrow_extract_regex_options,
              GARROW_TYPE_FUNCTION_OPTIONS)

static void
garrow_extract_regex_options_set_property(GObject *object,
                                          guint prop_id,
                                          const GValue *value,
                                          GParamSpec *pspec)
{
  auto options =
    garrow_extract_regex_options_get_raw(GARROW_EXTRACT_REGEX_OPTIONS(object));

  switch (prop_id) {
  case PROP_EXTRACT_REGEX_OPTIONS_PATTERN:
    options->pattern = g_value_get_string(value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    break;
  }
}

static void
garrow_extract_regex_options_get_property(GObject *object,
                                          guint prop_id,
                                          GValue *value,
                                          GParamSpec *pspec)
{
  auto options =
    garrow_extract_regex_options_get_raw(GARROW_EXTRACT_REGEX_OPTIONS(object));

  switch (prop_id) {
  case PROP_EXTRACT_REGEX_OPTIONS_PATTERN:
    g_value_set_string(value, options->pattern.c_str());
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    break;
  }
}

static void
garrow_extract_regex_options_init(GArrowExtractRegexOptions *object)
{
  auto priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
  priv->options = static_cast<arrow::compute::FunctionOptions *>(