8000 ENH: optimize STRING_compare by using memcmp by juliantaylor · Pull Request #4572 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: optimize STRING_compare by using memcmp #4572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2014
Merged
Changes from all commits
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
ENH: optimize STRING_compare by using memcmp
  • Loading branch information
juliantaylor committed May 22, 2014
commit 2f6da63938e516bb653b95f1de7b59b33c05a2fc
13 changes: 8 additions & 5 deletions numpy/core/src/multiarray/arraytypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "arrayobject.h"

#include "numpyos.h"
#include <string.h>


/*
Expand Down Expand Up @@ -2598,12 +2599,14 @@ STRING_compare(char *ip1, char *ip2, PyArrayObject *ap)
const unsigned char *c1 = (unsigned char *)ip1;
const unsigned char *c2 = (unsigned char *)ip2;
const size_t len = PyArray_DESCR(ap)->elsize;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I think it is correct that we compare all bytes, since only trailing 0-bytes are stripped (as\x00d\x00\x00 is 'as\x00d). Probably doesn't matter, butelsize` actually is int I think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, heh, in my mind I combined the old and new usage of i, so nvm.

size_t i;
int i;

for(i = 0; i < len; ++i) {
if (c1[i] != c2[i]) {
return (c1[i] > c2[i]) ? 1 : -1;
}
i = memcmp(c1, c2, len);
if (i > 0) {
return 1;
}
else if (i < 0) {
return -1;
}
return 0;
}
Expand Down
0