gemini-code-assist[bot] commented on code in PR #185:
URL: https://github.com/apache/tvm-ffi/pull/185#discussion_r2448647373


##########
python/tvm_ffi/libinfo.py:
##########
@@ -64,7 +64,17 @@ def get_dll_directories() -> list[str]:
         dll_path.extend(Path(p) for p in split_env_var("PATH", ":"))
     elif sys.platform.startswith("win32"):
         dll_path.extend(Path(p) for p in split_env_var("PATH", ";"))
-    return [str(path.resolve()) for path in dll_path if path.is_dir()]
+
+    valid_paths = []
+    for path in dll_path:
+        try:
+            if path.is_dir():
+                valid_paths.append(str(path.resolve()))
+        except OSError:
+            # need to ignore as resolve may fail if
+            # we don't have permission to access it
+            pass
+    return valid_paths

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The current implementation iterates through each path in `dll_path`, 
attempts to resolve it, and checks if it's a directory within a try-except 
block. This approach is good, but it can be made more efficient by combining 
the `is_dir()` check and `resolve()` call within the try block. This avoids 
redundant checks and improves readability.
   
   Consider moving the `path.is_dir()` check inside the `try` block to avoid 
calling `resolve()` unnecessarily when the path is not a directory. This can 
improve performance, especially when dealing with a large number of paths, some 
of which may not be directories.
   
   ```suggestion
       valid_paths = []
       for path in dll_path:
           try:
               path = path.resolve()  # Resolve the path
               if path.is_dir():  # Check if it's a directory after resolving
                   valid_paths.append(str(path))
           except OSError:
               # need to ignore as resolve may fail if
               # we don't have permission to access it
               pass
       return valid_paths
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to