OLD | NEW |
1 /** | 1 /** |
2 * common.js is a set of common functions used across all of skiaperf. | 2 * common.js is a set of common functions used across all of skiaperf. |
3 * | 3 * |
4 * Everything is scoped to 'sk' except $$ and $$$ which are global since they | 4 * Everything is scoped to 'sk' except $$ and $$$ which are global since they |
5 * are used so often. | 5 * are used so often. |
6 * | 6 * |
7 */ | 7 */ |
8 | 8 |
9 /** | 9 /** |
10 * $$ returns a real JS array of DOM elements that match the CSS query selector. | 10 * $$ returns a real JS array of DOM elements that match the CSS query selector. |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 sk.escapeHTML = function(s) { | 666 sk.escapeHTML = function(s) { |
667 return s.replace(/&/g, '&') | 667 return s.replace(/&/g, '&') |
668 .replace(/</g, '<') | 668 .replace(/</g, '<') |
669 .replace(/>/g, '>') | 669 .replace(/>/g, '>') |
670 .replace(/"/g, '"') | 670 .replace(/"/g, '"') |
671 .replace(/'/g, ''') | 671 .replace(/'/g, ''') |
672 .replace(/\//g, '/'); | 672 .replace(/\//g, '/'); |
673 | 673 |
674 } | 674 } |
675 | 675 |
| 676 // Returns true if the sorted arrays a and b |
| 677 // contain at least one element in common |
| 678 sk.sharesElement = function(a, b) { |
| 679 var i = 0; |
| 680 var j = 0; |
| 681 while (i < a.length && j < b.length) { |
| 682 if (a[i] < b[j]) { |
| 683 i++; |
| 684 } else if (b[j] < a[i]) { |
| 685 j++; |
| 686 } else { |
| 687 return true; |
| 688 } |
| 689 } |
| 690 return false; |
| 691 } |
| 692 |
676 // Polyfill for String.startsWith from | 693 // Polyfill for String.startsWith from |
677 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Ob
jects/String/startsWith#Polyfill | 694 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Ob
jects/String/startsWith#Polyfill |
678 // returns true iff the string starts with the given prefix | 695 // returns true iff the string starts with the given prefix |
679 if (!String.prototype.startsWith) { | 696 if (!String.prototype.startsWith) { |
680 String.prototype.startsWith = function(searchString, position) { | 697 String.prototype.startsWith = function(searchString, position) { |
681 position = position || 0; | 698 position = position || 0; |
682 return this.indexOf(searchString, position) === position; | 699 return this.indexOf(searchString, position) === position; |
683 }; | 700 }; |
684 } | 701 } |
685 | 702 |
686 return sk; | 703 return sk; |
687 }(); | 704 }(); |
OLD | NEW |