[Lldb-commits] [lldb] r281273 - This is the main part of a change to add breakpoint save and restore to lldb.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Mon Sep 12 18:55:05 PDT 2016


BTW, I was going over these, and this does not seem to me like a case where you want to do an early return.

The logic is:

Add some stuff to data
See if I found the UserSource key, if so add some more stuff
Then return data

It would not be clearer to do:

Add some stuff to data
See if I found the UserSource Key, if not return data
Otherwise add some more stuff to data
return data in another place.

That seems like asking for trouble when somebody wants to add another key, and misses the early return so they only get their stuff added when UserSource is present.

>From the examples given in the coding standards, I thought early return was more about: if there are a bunch of preconditions that need to be true before you can do the work of the function, do those checks up front.  That makes a lot of sense to me for the stated reason, but that's not what's going on here.

Jim

> On Sep 12, 2016, at 4:57 PM, Zachary Turner <zturner at google.com> wrote:
> 
> +BreakpointOptions::CommandData *
> +BreakpointOptions::CommandData::CreateFromStructuredData(
> +    StructuredData::Dictionary &options_dict, Error &error) {
> +  std::string script_source;
> +  CommandData *data = new CommandData();
> +  bool success = options_dict.GetValueForKeyAsBoolean(
> +      GetKey(OptionNames::StopOnError), data->stop_on_error);
> +
> +  success = options_dict.GetValueForKeyAsString(
> +      GetKey(OptionNames::ScriptSource), data->script_source);
> +
> +  StructuredData::Array *user_source;
> +  success = options_dict.GetValueForKeyAsArray(GetKey(OptionNames::UserSource),
> +                                               user_source);
> +  if (success) {
> Early return.
>  
> +    size_t num_elems = user_source->GetSize();
> +    for (size_t i = 0; i < num_elems; i++) {
> +      std::string elem_string;
> +      success = user_source->GetItemAtIndexAsString(i, elem_string);
> +      if (success)
> +        data->user_source.AppendString(elem_string);
> +    }
> +  }
> +  return data;
> +}
> +



More information about the lldb-commits mailing list