On x86 compilers without fastcall, simulate it when invoking traces and un-simulate...
[wine-gecko.git] / xpcom / glue / nsTHashtable.cpp
blobbf6e6dc63945d441a65180221ed9b75d4e227ecc
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is C++ hashtable templates.
17 * The Initial Developer of the Original Code is
18 * Benjamin Smedberg.
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsTHashtable.h"
39 #include "nsHashKeys.h"
40 #include "prbit.h"
42 PRUint32
43 HashString( const nsAString& aStr )
45 PRUint32 code = 0;
47 #ifdef MOZILLA_INTERNAL_API
48 nsAString::const_iterator begin, end;
49 aStr.BeginReading(begin);
50 aStr.EndReading(end);
51 #else
52 const PRUnichar *begin, *end;
53 PRUint32 len = NS_StringGetData(aStr, &begin);
54 end = begin + len;
55 #endif
57 while (begin != end) {
58 code = PR_ROTATE_LEFT32(code, 4) ^ PRUint32(*begin);
59 ++begin;
62 return code;
65 PRUint32
66 HashString( const nsACString& aStr )
68 PRUint32 code = 0;
70 #ifdef MOZILLA_INTERNAL_API
71 nsACString::const_iterator begin, end;
72 aStr.BeginReading(begin);
73 aStr.EndReading(end);
74 #else
75 const char *begin, *end;
76 PRUint32 len = NS_CStringGetData(aStr, &begin);
77 end = begin + len;
78 #endif
80 while (begin != end) {
81 code = PR_ROTATE_LEFT32(code, 4) ^ PRUint32(*begin);
82 ++begin;
85 return code;
88 PRUint32
89 HashString(const char *str)
91 PRUint32 code = 0;
93 while (*str) {
94 code = PR_ROTATE_LEFT32(code, 4) ^ PRUint32(*str);
95 ++str;
98 return code;
101 PRUint32
102 HashString(const PRUnichar *str)
104 PRUint32 code = 0;
106 while (*str) {
107 code = PR_ROTATE_LEFT32(code, 4) ^ PRUint32(*str);
108 ++str;
111 return code;
114 PLDHashOperator
115 PL_DHashStubEnumRemove(PLDHashTable *table,
116 PLDHashEntryHdr *entry,
117 PRUint32 ordinal,
118 void *userarg)
120 return PL_DHASH_REMOVE;
123 PRUint32 nsIDHashKey::HashKey(const nsID* id)
125 PRUint32 h = id->m0;
126 PRUint32 i;
128 h = PR_ROTATE_LEFT32(h, 4) ^ id->m1;
129 h = PR_ROTATE_LEFT32(h, 4) ^ id->m2;
131 for (i = 0; i < 8; i++)
132 h = PR_ROTATE_LEFT32(h, 4) ^ id->m3[i];
134 return h;