All of lore.kernel.org
 help / color / mirror / Atom feed
From: Valentin Schneider <vschneid@redhat.com>
To: linux-rt-users@vger.kernel.org
Cc: John Kacur <jkacur@redhat.com>, Clark Williams <williams@redhat.com>
Subject: [PATCH 3/3] rteval: systopology: Slight CpuList.__expand_cpulist() cleanup
Date: Tue, 19 Apr 2022 17:14:43 +0100	[thread overview]
Message-ID: <20220419161443.89674-4-vschneid@redhat.com> (raw)
In-Reply-To: <20220419161443.89674-1-vschneid@redhat.com>

This method currently aggregates CPUs into a list, then converts this to
set and then back to list. The aggregation can instead be done directly
into a set.

(as an offside, it would make more sense for CpuList to have its storage be
a set in the first place as duplicate CPU ids don't make sense for it, but
that's a separate discussion :-))

The integer conversion of the "a-b" pattern can also be condensed into a
single map() expression.

Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
 rteval/systopology.py | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/rteval/systopology.py b/rteval/systopology.py
index b2da7bb..2a28f9c 100644
--- a/rteval/systopology.py
+++ b/rteval/systopology.py
@@ -102,20 +102,19 @@ class CpuList:
         """ expand a range string into an array of cpu numbers
         don't error check against online cpus
         """
-        result = []
-
         if not cpulist:
-            return result
+            return []
+
+        result = set()
 
         for part in cpulist.split(','):
             if '-' in part:
-                a, b = part.split('-')
-                a, b = int(a), int(b)
-                result.extend(list(range(a, b + 1)))
+                a, b = map(int, part.split('-'))
+                result |= set(range(a, b + 1))
             else:
                 a = int(part)
-                result.append(a)
-        return [int(i) for i in list(set(result))]
+                result |= {a}
+        return list(result)
 
     def getcpulist(self):
         """ return the list of cpus tracked """
-- 
2.27.0


  parent reply	other threads:[~2022-04-19 16:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19 16:14 [PATCH 0/3] rteval: Offline NUMA node bugfix Valentin Schneider
2022-04-19 16:14 ` [PATCH 1/3] rteval: systopology: Fix offline NUMA node parsing Valentin Schneider
2022-04-29 19:54   ` John Kacur
2022-04-19 16:14 ` [PATCH 2/3] rteval: kcompile: Fix offline node handling Valentin Schneider
2022-04-29 20:21   ` John Kacur
2022-04-19 16:14 ` Valentin Schneider [this message]
2022-04-29 20:53   ` [PATCH 3/3] rteval: systopology: Slight CpuList.__expand_cpulist() cleanup John Kacur
2022-05-03 10:26     ` Valentin Schneider

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220419161443.89674-4-vschneid@redhat.com \
    --to=vschneid@redhat.com \
    --cc=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.