139 EXPORT_C void CEnvironment::SetL(const TDesC& aKey, const TDesC& aValue) |
139 EXPORT_C void CEnvironment::SetL(const TDesC& aKey, const TDesC& aValue) |
140 { |
140 { |
141 WaitLC(); |
141 WaitLC(); |
142 |
142 |
143 HBufC** valPtr = iVars.Find(aKey); |
143 HBufC** valPtr = iVars.Find(aKey); |
144 HBufC* currentValue = NULL; |
|
145 if (valPtr) currentValue = *valPtr; |
|
146 |
144 |
147 if (valPtr == NULL && iParentEnv) |
145 if (valPtr == NULL && iParentEnv) |
148 { |
146 { |
149 // If we don't have it, and we have a parent env, we should pass the request through to it. |
147 // If we don't have it, and we have a parent env, we should pass the request through to it. |
150 iParentEnv->SetL(aKey, aValue); |
148 iParentEnv->SetL(aKey, aValue); |
151 } |
149 } |
|
150 else if (valPtr) |
|
151 { |
|
152 // The key is present in the hash. |
|
153 HBufC* currentValue = *valPtr; |
|
154 if (currentValue && (currentValue->Des().MaxLength() >= aValue.Length())) |
|
155 { |
|
156 // If the existing HBufC is big enough, simply copy. |
|
157 // Note, currentValue will be NULL if this is the first time a 'local' variable is being set. |
|
158 currentValue->Des().Copy(aValue); |
|
159 } |
|
160 else |
|
161 { |
|
162 // Otherwise allocate a new HBufC. |
|
163 *valPtr = aValue.AllocL(); |
|
164 delete currentValue; |
|
165 } |
|
166 } |
152 else |
167 else |
153 { |
168 { |
154 if (currentValue) |
169 // New key. |
155 { |
170 HBufC* newVal = aValue.AllocLC(); |
156 // If we already have a value in the hash, just update it if possible |
171 iVars.InsertL(aKey, newVal); |
157 TPtr ptr = currentValue->Des(); |
172 CleanupStack::Pop(newVal); |
158 if (ptr.MaxLength() >= aValue.Length()) |
|
159 { |
|
160 ptr.Copy(aValue); |
|
161 CleanupStack::PopAndDestroy(); // Release lock |
|
162 return; |
|
163 } |
|
164 } |
|
165 } |
173 } |
166 |
174 |
167 HBufC* newVal = aValue.AllocLC(); |
|
168 iVars.InsertL(aKey, newVal); |
|
169 delete currentValue; |
|
170 CleanupStack::Pop(newVal); |
|
171 CleanupStack::PopAndDestroy(); // Release lock |
175 CleanupStack::PopAndDestroy(); // Release lock |
172 } |
176 } |
173 |
177 |
174 HBufC* CEnvironment::Get(const TDesC& aKey) const |
178 HBufC* CEnvironment::Get(const TDesC& aKey) const |
175 { |
179 { |