Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove unused buffer
  • Loading branch information
sweeneyde committed May 2, 2021
commit d7160946eb72a4ba264336d9cb732ee45efcaf4c
8 changes: 2 additions & 6 deletions Python/suggestions.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,23 @@ calculate_suggestions(PyObject *dir,
return NULL;
}

Py_ssize_t suggestion_distance = PyUnicode_GetLength(name);
Py_ssize_t suggestion_distance = PY_SSIZE_T_MAX;
PyObject *suggestion = NULL;
Py_ssize_t name_size;
const char *name_str = PyUnicode_AsUTF8AndSize(name, &name_size);
if (name_str == NULL) {
return NULL;
}
size_t *work_buffer = PyMem_Calloc(name_size, sizeof(size_t));
if (work_buffer == NULL) {
return NULL;
}

for (int i = 0; i < dir_size; ++i) {
PyObject *item = PyList_GET_ITEM(dir, i);
Py_ssize_t item_size;
const char *item_str = PyUnicode_AsUTF8AndSize(item, &item_size);
if (item_str == NULL) {
PyMem_Free(work_buffer);
return NULL;
}
Py_ssize_t max_distance = (name_size + item_size + 3) * MOVE_COST / 6;
max_distance = Py_MIN(max_distance, suggestion_distance);
Py_ssize_t current_distance =
levenshtein_distance(name_str, name_size,
item_str, item_size, max_distance);
Expand Down