aboutsummaryrefslogtreecommitdiffstats
path: root/translate.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-12-06 21:53:57 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-12-06 21:53:57 +0000
commit745c13c84e2f757ac38147e6434bb66c1f941498 (patch)
treeb543532d6e4a5b54fc05200ecb5e263f02aa6780 /translate.c
parent3f10cfbab8d6b8f8183651cf96a544e19e4abcaf (diff)
Minor translation performance improvement (bug #2987, not that patch though)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4393 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'translate.c')
-rwxr-xr-xtranslate.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/translate.c b/translate.c
index 2bbda14da..0fd8f0951 100755
--- a/translate.c
+++ b/translate.c
@@ -3,9 +3,9 @@
*
* Translate via the use of pseudo channels
*
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999-2004, Digium, Inc.
*
- * Mark Spencer <markster@linux-support.net>
+ * Mark Spencer <markster@digium.com>
*
* This program is free software, distributed under the terms of
* the GNU General Public License
@@ -442,33 +442,40 @@ int ast_translator_best_choice(int *dst, int *srcs)
int bestdst=0;
int cur = 1;
int besttime=999999999;
- ast_mutex_lock(&list_lock);
- for (y=0;y<MAX_FORMAT;y++) {
- if ((cur & *dst) && (cur & *srcs)) {
- /* This is a common format to both. Pick it if we don't have one already */
- besttime=0;
- bestdst = cur;
- best = cur;
- break;
- }
- if (cur & *dst)
- for (x=0;x<MAX_FORMAT;x++) {
- if (tr_matrix[x][y].step && /* There's a step */
- (tr_matrix[x][y].cost < besttime) && /* We're better than what exists now */
- (*srcs & (1 << x))) /* x is a valid source format */
- {
- best = 1 << x;
- bestdst = cur;
- besttime = tr_matrix[x][y].cost;
- }
+ if ((*dst) & (*srcs)) {
+ /* We have a format in common */
+ for (y=0;y<MAX_FORMAT;y++) {
+ if ((cur & *dst) && (cur & *srcs)) {
+ /* This is a common format to both. Pick it if we don't have one already */
+ besttime=0;
+ bestdst = cur;
+ best = cur;
}
- cur = cur << 1;
+ cur = cur << 1;
+ }
+ } else {
+ /* We will need to translate */
+ ast_mutex_lock(&list_lock);
+ for (y=0;y<MAX_FORMAT;y++) {
+ if (cur & *dst)
+ for (x=0;x<MAX_FORMAT;x++) {
+ if (tr_matrix[x][y].step && /* There's a step */
+ (tr_matrix[x][y].cost < besttime) && /* We're better than what exists now */
+ (*srcs & (1 << x))) /* x is a valid source format */
+ {
+ best = 1 << x;
+ bestdst = cur;
+ besttime = tr_matrix[x][y].cost;
+ }
+ }
+ cur = cur << 1;
+ }
+ ast_mutex_unlock(&list_lock);
}
if (best > -1) {
*srcs = best;
*dst = bestdst;
best = 0;
}
- ast_mutex_unlock(&list_lock);
return best;
}