summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYouka <spanknebel.borken@t-online.de>2014-11-09 20:11:57 +0100
committerOleg Oshmyan <chortos@inbox.lv>2014-11-13 23:35:14 +0100
commitf7af5424c67694e5812685e0a9d463446a8e4fa7 (patch)
treeae7069a3ca9f645eda953b7c1e62417d62fadcb3
parent6fdfcabb95ddc0f94551eb38ee6e6dcfcdd6301f (diff)
downloadlibass-f7af5424c67694e5812685e0a9d463446a8e4fa7.tar.bz2
libass-f7af5424c67694e5812685e0a9d463446a8e4fa7.tar.xz
Simplify ass_utils.c code
Mainly cosmetic, but maybe some optimizations the compiler misses.
-rw-r--r--libass/ass_utils.c70
1 files changed, 22 insertions, 48 deletions
diff --git a/libass/ass_utils.c b/libass/ass_utils.c
index efb96a6..27fc025 100644
--- a/libass/ass_utils.c
+++ b/libass/ass_utils.c
@@ -38,38 +38,33 @@ int has_sse2(void)
{
uint32_t eax = 1, ebx, ecx, edx;
ass_get_cpuid(&eax, &ebx, &ecx, &edx);
- return (!!(edx & (1 << 26)));
+ return (edx >> 26) & 0x1;
}
int has_avx(void)
{
uint32_t eax = 1, ebx, ecx, edx;
ass_get_cpuid(&eax, &ebx, &ecx, &edx);
- if(!(ecx & (1 << 27))){
+ if(!(ecx & (1 << 27))) // not OSXSAVE
return 0;
- }
uint32_t misc = ecx;
eax = 0;
ass_get_cpuid(&eax, &ebx, &ecx, &edx);
- if((ecx & (0x2 | 0x4)) != (0x2 | 0x4)){
- return 0;
- }
- return (!!(misc & (1 << 28)));
+ return (ecx & 0x6) == 0x6 ? (misc >> 28) & 0x1 : 0; // check high bits are relevant, then AVX support
}
int has_avx2(void)
{
uint32_t eax = 7, ebx, ecx, edx;
ass_get_cpuid(&eax, &ebx, &ecx, &edx);
- return (!!(ebx & (1 << 5))) && has_avx();
+ return (ebx >> 5) & has_avx();
}
#endif // ASM
void *ass_aligned_alloc(size_t alignment, size_t size)
{
- if (alignment & (alignment - 1))
- abort(); // not a power of 2
+ assert(!(alignment & (alignment - 1))); // alignment must be power of 2
if (size >= SIZE_MAX - alignment - sizeof(void *))
return NULL;
char *allocation = malloc(size + sizeof(void *) + alignment - 1);
@@ -125,46 +120,32 @@ void rskip_spaces(char **str, char *limit)
int mystrtoi(char **p, int *res)
{
- double temp_res;
char *start = *p;
- temp_res = ass_strtod(*p, p);
+ double temp_res = ass_strtod(*p, p);
*res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5));
- if (*p != start)
- return 1;
- else
- return 0;
+ return *p != start;
}
int mystrtoll(char **p, long long *res)
{
- double temp_res;
char *start = *p;
- temp_res = ass_strtod(*p, p);
+ double temp_res = ass_strtod(*p, p);
*res = (long long) (temp_res + (temp_res > 0 ? 0.5 : -0.5));
- if (*p != start)
- return 1;
- else
- return 0;
+ return *p != start;
}
int mystrtou32(char **p, int base, uint32_t *res)
{
char *start = *p;
*res = strtoll(*p, p, base);
- if (*p != start)
- return 1;
- else
- return 0;
+ return *p != start;
}
int mystrtod(char **p, double *res)
{
char *start = *p;
*res = ass_strtod(*p, p);
- if (*p != start)
- return 1;
- else
- return 0;
+ return *p != start;
}
uint32_t string2color(ASS_Library *library, char *p, int hex)
@@ -181,23 +162,20 @@ uint32_t string2color(ASS_Library *library, char *p, int hex)
if (*p == 'H' || *p == 'h') {
++p;
mystrtou32(&p, 16, &color);
- } else {
+ } else
mystrtou32(&p, base, &color);
- }
while (*p == '&' || *p == 'H')
++p;
- {
- unsigned char *tmp = (unsigned char *) (&color);
- unsigned char b;
- b = tmp[0];
- tmp[0] = tmp[3];
- tmp[3] = b;
- b = tmp[1];
- tmp[1] = tmp[2];
- tmp[2] = b;
- }
+ unsigned char *tmp = (unsigned char *) (&color);
+ unsigned char b;
+ b = tmp[0];
+ tmp[0] = tmp[3];
+ tmp[3] = b;
+ b = tmp[1];
+ tmp[1] = tmp[2];
+ tmp[2] = b;
return color;
}
@@ -206,11 +184,7 @@ uint32_t string2color(ASS_Library *library, char *p, int hex)
char parse_bool(char *str)
{
skip_spaces(&str);
- if (!strncasecmp(str, "yes", 3))
- return 1;
- else if (strtol(str, NULL, 10) > 0)
- return 1;
- return 0;
+ return !strncasecmp(str, "yes", 3) || strtol(str, NULL, 10) > 0;
}
int parse_ycbcr_matrix(char *str)
@@ -227,7 +201,7 @@ int parse_ycbcr_matrix(char *str)
// so we can simply chop off the rest of the input.
char buffer[16];
size_t n = FFMIN(end - str, sizeof buffer - 1);
- strncpy(buffer, str, n);
+ memcpy(buffer, str, n);
buffer[n] = '\0';
if (!strcasecmp(buffer, "none"))