Przeglądaj źródła

Use range for loops in some places

Bryan Drewery 7 lat temu
rodzic
commit
1c1f6d950a
3 zmienionych plików z 4 dodań i 13 usunięć
  1. 2 4
      src/cmds.cc
  2. 1 2
      src/misc.cc
  3. 1 7
      src/mod/channels.mod/chanmisc.cc

+ 2 - 4
src/cmds.cc

@@ -922,8 +922,7 @@ static void cmd_groups(int idx, char *par)
     if (u->bot && bot_hublevel(u) == 999) {
       // Gather all the groups for this bot
       botGroups[u->handle] = bd::String(var_get_bot_data(u, "groups", true)).split(",");
-      for (size_t i = 0; i < botGroups[u->handle].length(); ++i) {
-        const bd::String group(botGroups[u->handle][i]);
+      for (const auto& group : botGroups[u->handle]) {
         if (group.length() > maxGroupLen) {
           maxGroupLen = group.length();
         }
@@ -943,8 +942,7 @@ static void cmd_groups(int idx, char *par)
     dprintf(idx, "Total groups: %zu/%zu\n", botGroups[botnick].length(), allgroups.length());
   } else {
     // Display all groups and which bots are in them
-    for (size_t i = 0; i < allgroups.length(); ++i) {
-      const bd::String group(allgroups[i]);
+    for (const auto& group : allgroups) {
       const bd::Array<bd::String> bots(groupBots[group]);
       dumplots(idx, bd::String::printf("%-*s: ", int(maxGroupLen), group.c_str()).c_str(), static_cast<bd::String>(bots.join(" ")).c_str());
     }

+ 1 - 2
src/misc.cc

@@ -481,8 +481,7 @@ void show_channels(int idx, char *handle)
       dprintf(idx, "%s %s access to %zu channel%s:\n", handle ? u->handle : "You", handle ? "has" : "have", channelNames.length(), (channelNames.length() > 1) ? "s" : "");
     }
 
-    for (size_t i = 0; i < channelNames.length(); ++i) {
-      const bd::String chname(channelNames[i]);
+    for (const auto& chname : channelNames) {
       const struct chanset_t* chan = findchan_by_dname(chname);
       dprintf(idx, format, !conf.bot->hub && me_op(chan) ? '@' : ' ', chan->dname, ((conf.bot->hub && channel_inactive(chan)) || (!conf.bot->hub && !shouldjoin(chan))) ? "(inactive) " : "",
           channel_privchan(chan) ? "(private)  " : "", chan->manop ? "(no manop) " : "", 

+ 1 - 7
src/mod/channels.mod/chanmisc.cc

@@ -1047,16 +1047,10 @@ void clear_channel(struct chanset_t *chan, bool reset)
 
   if (chan->channel.cached_members) {
     if (chan->channel.cached_members->size()) {
-      bd::Array<bd::String> member_uhosts(chan->channel.cached_members->keys());
-      for (size_t i = 0; i < member_uhosts.length(); ++i) {
-        const bd::String uhost(member_uhosts[i]);
-
+      for (const auto& uhost : chan->channel.cached_members->keys()) {
         // Delete the cached member
         m = (*chan->channel.cached_members)[uhost];
         delete_member(m);
-
-        // Remove the cached member (not technically needed as it is deleted below, but for completeness.)
-        chan->channel.cached_members->remove(uhost);
       }
     }
     delete chan->channel.cached_members;