From be5072916246aa13af783e90440a9fcad1bde812 Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Thu, 16 May 2024 03:43:43 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Speed=20up=20get=5Fset()?= =?UTF-8?q?=20by=2051%=20Your=20existing=20function=20is=20pretty=20effici?= =?UTF-8?q?ent,=20as=20it=20already=20uses=20set=20comprehension=20which?= =?UTF-8?q?=20is=20quite=20speedy=20in=20Python.=20However,=20there=20coul?= =?UTF-8?q?d=20be=20a=20minor=20optimization=20if=20you=20use=20map=20inst?= =?UTF-8?q?ead=20of=20the=20generator=20expression.=20In=20Python,=20map()?= =?UTF-8?q?=20function=20is=20kind=20of=20faster=20than=20list=20comprehen?= =?UTF-8?q?sion=20because=20it=20directly=20produces=20a=20list=20instead?= =?UTF-8?q?=20of=20creating=20a=20generator=20first.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The optimized code looks like this. Please note code readability is also important. If the performance gain of using map() over a generator is marginal or unnoticeable, it's fine to stick with the original implementation in order to have more readable code. --- posthog/settings/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/posthog/settings/utils.py b/posthog/settings/utils.py index eead270c7bd7d..3832da4613838 100644 --- a/posthog/settings/utils.py +++ b/posthog/settings/utils.py @@ -36,6 +36,4 @@ def get_list(text: str) -> list[str]: def get_set(text: str) -> set[str]: - if not text: - return set() - return {item.strip() for item in text.split(",")} + return set() if not text else set(map(str.strip, text.split(",")))